Documentation ¶
Index ¶
- type Engine
- func (w *Engine) Drain()
- func (w *Engine) Enqueue(job *Job, opts *JobOptions) error
- func (w *Engine) EnqueueAt(t time.Time, job *Job, opts *JobOptions) error
- func (w *Engine) EnqueueIn(d time.Duration, job *Job, opts *JobOptions) error
- func (w *Engine) Info() []string
- func (w *Engine) Jobs() []*Job
- func (w *Engine) ProcessTask(ctx context.Context, job *Job)
- func (w *Engine) Run()
- func (w *Engine) Use(handlers ...MiddlewareFunc)
- type Handler
- type HandlerFunc
- type Job
- type JobOptions
- type JobPayload
- type MiddlewareFunc
- type MockedHandler
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 jobs.
func NewEngine ¶
func NewEngine(asset *support.Asset, config *support.Config, dbManager *record.Engine, l *support.Logger) *Engine
NewEngine initializes a worker to process background jobs.
func (*Engine) Drain ¶
func (w *Engine) Drain()
Drain simulates job processing by removing them, only available for unit test with APPY_ENV=test.
func (*Engine) Enqueue ¶
func (w *Engine) Enqueue(job *Job, opts *JobOptions) error
Enqueue enqueues job to be processed immediately.
Enqueue returns nil if the job is enqueued successfully, otherwise returns an error.
func (*Engine) EnqueueAt ¶
EnqueueAt schedules job to be enqueued at the specified time.
It returns nil if the job is scheduled successfully, otherwise returns an error.
func (*Engine) EnqueueIn ¶
EnqueueIn schedules job to be enqueued after the specified delay.
It returns nil if the job is scheduled successfully, otherwise returns an error.
func (*Engine) Jobs ¶
Jobs returns the enqueued jobs, only available for unit test with APPY_ENV=test.
func (*Engine) ProcessTask ¶
ProcessTask dispatches the job to the handler whose pattern most closely matches the job type.
func (*Engine) Run ¶
func (w *Engine) Run()
Run starts running the worker to process background jobs.
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 jobs.
ProcessTask should return nil if the processing of a background job is successful.
If ProcessTask return a non-nil error or panics, the background job 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 JobOptions ¶
type JobOptions struct { Deadline time.Time MaxRetry int Queue string Timeout time.Duration UniqueTTL time.Duration }
JobOptions specifies how a job should be processed.
type JobPayload ¶
JobPayload holds arbitrary data needed for job processing.
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 MockedHandler ¶
MockedHandler is used for mocking in unit test.
func NewMockedHandler ¶
func NewMockedHandler() *MockedHandler
NewMockedHandler initializes a mocked Handler instance that is useful for unit test.
func (*MockedHandler) ProcessTask ¶
func (h *MockedHandler) ProcessTask(ctx context.Context, job *Job) error
ProcessTask mocks the job processing functionality that is useful for unit test.