Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
WithConcurrencyFactor sets the concurrency factor
func WithInstrumentationClient ¶
func WithInstrumentationClient(instrumentationClient *instrumentation.Client) Option
WithInstrumentationClient sets the instrumentation client
func WithRedisAddress ¶
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 ¶
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 ¶
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` 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.