Documentation ¶
Index ¶
- type Engine
- func (w *Engine) Drain()
- func (w *Engine) Enqueue(task *Task, opts *TaskOptions) (*TaskResult, error)
- func (w *Engine) Info() []string
- func (w *Engine) ProcessTask(ctx context.Context, task *Task) error
- func (w *Engine) Run() error
- func (w *Engine) Tasks() []*Task
- func (w *Engine) Use(handlers ...MiddlewareFunc)
- type Handler
- type HandlerFunc
- type MiddlewareFunc
- type Task
- type TaskOptions
- type TaskPayload
- type TaskResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct { *asynq.Server *asynq.Client *asynq.ServeMux asynq.RedisConnOpt // contains filtered or unexported fields }
Engine processes the background tasks.
func (*Engine) Drain ¶
func (w *Engine) Drain()
Drain simulates task processing by removing them, only available for unit test with APPY_ENV=test.
func (*Engine) Enqueue ¶
func (w *Engine) Enqueue(task *Task, opts *TaskOptions) (*TaskResult, error)
Enqueue enqueues task to be processed asynchronously.
Enqueue returns nil if the task is enqueued successfully, otherwise returns a non-nil error.
The argument opts specifies the behavior of task processing. If there are conflicting TaskOption values the last one overrides others. By default, max retry is set to 25 and timeout is set to 30 minutes. If no ProcessAt or ProcessIn options are passed, the task will be processed immediately.
func (*Engine) ProcessTask ¶
ProcessTask dispatches the task to the handler whose pattern most closely matches the task type.
func (*Engine) Tasks ¶
Tasks returns the enqueued tasks, only available for unit test with APPY_ENV=test.
func (*Engine) Use ¶
func (w *Engine) Use(handlers ...MiddlewareFunc)
Use appends a MiddlewareFunc to the chain. Middlewares are executed in the order that they are applied to the ServeMux.
type Handler ¶
Handler processes background tasks.
ProcessTask should return nil if the processing of a background task is successful.
If ProcessTask return a non-nil error or panics, the background task will be retried after delay.
type HandlerFunc ¶
type HandlerFunc = asynq.HandlerFunc
HandlerFunc is an adapter to allow the use of ordinary functions as a Handler. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
type MiddlewareFunc ¶
type MiddlewareFunc = asynq.MiddlewareFunc
MiddlewareFunc is a function which receives an Handler and returns another Handler. Typically, the returned handler is a closure which does something with the context and task passed to it, and then calls the handler passed as parameter to the MiddlewareFunc.
type TaskOptions ¶
type TaskOptions struct { Deadline time.Time MaxRetry int ProcessAt time.Time ProcessIn time.Duration Queue string Timeout time.Duration UniqueTTL time.Duration }
TaskOptions specifies how a task should be processed.
type TaskPayload ¶
TaskPayload holds arbitrary data needed for task processing.