worker

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

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

func (w *Engine) EnqueueAt(t time.Time, job *Job, opts *JobOptions) error

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

func (w *Engine) EnqueueIn(d time.Duration, job *Job, opts *JobOptions) error

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) Info

func (w *Engine) Info() []string

Info returns the worker info.

func (*Engine) Jobs

func (w *Engine) Jobs() []*Job

Jobs returns the enqueued jobs, only available for unit test with APPY_ENV=test.

func (*Engine) ProcessTask

func (w *Engine) ProcessTask(ctx context.Context, job *Job)

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

type Handler = asynq.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 Job

type Job = asynq.Task

Job represents a unit of work to be performed.

func NewJob

func NewJob(id string, data map[string]interface{}) *Job

NewJob initializes a job with a unique identifier and its data for background job processing.

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

type JobPayload = asynq.Payload

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

type MockedHandler struct {
	mock.Mock
}

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.

Jump to

Keyboard shortcuts

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