worker

package
v1.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRedisAddressNotSet          = errors.New("redis address not set")
	ErrRedisPasswordNotSet         = errors.New("redis password not set")
	ErrConcurrencyFactorNotSet     = errors.New("concurrency factor not set")
	ErrTaskHandlerNotSet           = errors.New("task handler not set")
	ErrInstrumentationClientNotSet = errors.New("instrumentation client not set")
)

Functions

This section is empty.

Types

type Option

type Option func(*Worker)

Option is a function that configures a worker

func WithConcurrencyFactor

func WithConcurrencyFactor(concurrencyFactor int) Option

WithConcurrencyFactor sets the concurrency factor

func WithInstrumentationClient

func WithInstrumentationClient(instrumentationClient *instrumentation.Client) Option

WithInstrumentationClient sets the instrumentation client

func WithRedisAddress

func WithRedisAddress(address string) Option

WithRedisAddress sets the redis address

func WithTaskHandler

func WithTaskHandler(taskHandler taskhandler.ITaskHandler) Option

WithTaskHandler sets the task handler

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

`type Worker struct` is defining a new struct type called `Worker`. This struct type has three fields: `redisAddress` of type string, `concurrencyFactor` of type int, and `srv` of type `*asynq.Server`. These fields represent the configuration and state of a worker that will process tasks from a Redis server using the `asynq` package.

func NewWorker

func NewWorker(opts ...Option) (*Worker, error)

NewWorker creates a new worker

```go

worker, err := NewWorker(
	WithRedisAddress("localhost:6379"),
	WithConcurrencyFactor(10),
)
if err != nil {
	return err
}

defer worker.Stop()

// start the worker asynchronously in another go routine
go worker.Start()

```

func (*Worker) Start

func (w *Worker) Start() error

Start starts the worker ```go

worker, err := NewWorker(
	WithRedisAddress("localhost:6379"),
	WithConcurrencyFactor(10),
)
if err != nil {
	return err
}

defer worker.Stop()

// start the worker asynchronously in another go routine
go worker.Start()

```

func (*Worker) Stop

func (w *Worker) Stop()

Stop stops the worker ```go

worker, err := NewWorker(
	WithRedisAddress("localhost:6379"),
	WithConcurrencyFactor(10),
)
if err != nil {
	return err
}

defer worker.Stop()

func (*Worker) Validate

func (w *Worker) Validate() error

`func (w *Worker) Validate() error` is a method of the `Worker` struct that validates whether the required fields of the worker have been set or not. It returns an error if any of the required fields are not set. This method is called during the creation of a new worker instance to ensure that the worker is properly configured before it is started.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL