Documentation ¶
Index ¶
- func AddModelIndexes(catalog *coal.Catalog, removeAfter time.Duration)
- func Cancel(ctx context.Context, store *coal.Store, job Job, reason string) error
- func Complete(ctx context.Context, store *coal.Store, job Job) error
- func Dequeue(ctx context.Context, store *coal.Store, job Job, timeout time.Duration) (bool, int, error)
- func Enqueue(ctx context.Context, store *coal.Store, job Job, ...) (bool, error)
- func Fail(ctx context.Context, store *coal.Store, job Job, reason string, ...) error
- type Base
- type Blueprint
- type Context
- type Error
- type Event
- type Job
- type Meta
- type Model
- type Options
- type Queue
- func (q *Queue) Action(methods []string, cb func(ctx *fire.Context) Blueprint) *fire.Action
- func (q *Queue) Add(task *Task)
- func (q *Queue) Callback(matcher fire.Matcher, cb func(ctx *fire.Context) Blueprint) *fire.Callback
- func (q *Queue) Close()
- func (q *Queue) Enqueue(ctx context.Context, job Job, delay, isolation time.Duration) (bool, error)
- func (q *Queue) Run() chan struct{}
- type State
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddModelIndexes ¶ added in v0.28.0
AddModelIndexes will add job indexes to the specified catalog. If a duration is specified, completed and cancelled jobs are automatically removed when their finished timestamp falls behind the specified duration.
func Cancel ¶ added in v0.21.0
Cancel will cancel the specified job with the provided reason. Only jobs in the "dequeued" state can be cancelled.
func Complete ¶ added in v0.21.0
Complete will complete the specified job. Only jobs in the "dequeued" state can be completed.
func Dequeue ¶ added in v0.21.0
func Dequeue(ctx context.Context, store *coal.Store, job Job, timeout time.Duration) (bool, int, error)
Dequeue will dequeue the specified job. The provided timeout will be set to allow the job to be dequeued if the worker failed to set its state. Only jobs in the "enqueued", "dequeued" (passed timeout) or "failed" state are dequeued. It will return whether a job has been dequeued.
func Enqueue ¶
func Enqueue(ctx context.Context, store *coal.Store, job Job, delay, isolation time.Duration) (bool, error)
Enqueue will enqueue the specified job with the provided delay and isolation. It will return whether a job has been enqueued. If the context carries a transaction it must be associated with the specified store.
Types ¶
type Base ¶ added in v0.28.0
Base can be embedded in a struct to turn it into a job.
func (*Base) GetAccessor ¶ added in v0.28.0
GetAccessor implements the Model interface.
type Blueprint ¶ added in v0.22.1
type Blueprint struct { // The job to be enqueued. Job Job // The job delay. If specified, the job will not be dequeued until the // specified duration has passed. Delay time.Duration // The job isolation. If specified, the job will only be enqueued if no job // has been executed in the specified duration. Isolation time.Duration }
Blueprint describes a queueable job.
type Context ¶ added in v0.20.0
type Context struct { // The context that is cancelled when the task timeout has been reached. // // Values: opentracing.Span, *xo.Tracer context.Context // The executed job. Job Job // The current attempt to execute the job. // // Usage: Read Only Attempt int // The task that executes this job. // // Usage: Read Only Task *Task // The queue this job was dequeued from. // // Usage: Read Only Queue *Queue // The current tracer. // // Usage: Read Only Tracer *xo.Tracer }
Context holds and stores contextual data.
type Error ¶
Error is used to control retry an cancellation. These errors are expected and are not forwarded to the reporter.
type Event ¶ added in v0.28.0
type Event struct { // The time when the event was reported. Timestamp time.Time `json:"timestamp"` // The new state of the job. State State `json:"state"` // The reason when failed or cancelled. Reason string `json:"reason"` }
Event is logged during a jobs execution.
type Job ¶
type Job interface { ID() coal.ID Validate() error GetBase() *Base GetAccessor(interface{}) *stick.Accessor }
Job is a structure used to encode a job.
type Meta ¶ added in v0.28.0
type Meta struct { // The jobs type. Type reflect.Type // The jobs name. Name string // The used transfer coding. Coding stick.Coding // The accessor. Accessor *stick.Accessor }
Meta contains meta information about a job.
type Model ¶
type Model struct { coal.Base `json:"-" bson:",inline" coal:"jobs"` // The job name. Name string `json:"name"` // The job label. Label string `json:"label"` // The encoded job data. Data stick.Map `json:"data"` // The current state of the job. State State `json:"state"` // The time when the job was created. Created time.Time `json:"created-at" bson:"created_at"` // The time when the job is available for execution. Available time.Time `json:"available-at" bson:"available_at"` // The time when the last or current execution started. Started *time.Time `json:"started-at" bson:"started_at"` // The time when the last execution ended (completed, failed or cancelled). Ended *time.Time `json:"ended-at" bson:"ended_at"` // The time when the job was successfully executed (completed or cancelled). Finished *time.Time `json:"finished-at" bson:"finished_at"` // Attempts is incremented with each execution attempt. Attempts int `json:"attempts"` // The individual job events. Events []Event `json:"events"` }
Model stores an executable job.
type Options ¶ added in v0.28.0
type Options struct { // The store used to manage jobs. Store *coal.Store // The maximum amount of lag that should be applied to every dequeue attempt. // // By default multiple workers compete with each other when getting jobs // from the same queue. An artificial lag limits multiple simultaneous // dequeue attempts and allows the worker with the smallest lag to dequeue // the job and inform the other workers to limit parallel dequeue attempts. // // Default: 100ms. MaxLag time.Duration // The duration after which a job may be returned again from the board. // // It may take some time until the board is updated with the new state of // the job after a dequeue. The block period prevents another worker from // simultaneously trying to dequeue the job. If the initial worker failed to // dequeue the job it will be available again after the defined period. // // Default: 10s. BlockPeriod time.Duration // The callback that is called with job errors. Reporter func(error) }
Options defines queue options.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue manages job queueing.
func (*Queue) Action ¶ added in v0.23.0
Action is a factory to create an action that can be used to enqueue jobs.
func (*Queue) Callback ¶
Callback is a factory to create callbacks that can be used to enqueue jobs during request processing.
type State ¶ added in v0.28.0
type State string
State defines the states of a job.
type Task ¶
type Task struct { // The job this task should execute. Job Job // The callback that is called with jobs for execution. The handler may // return errors formatted with E to manually control the state of the job. Handler func(ctx *Context) error // The callback that is called once a job has been completed or cancelled. Notifier func(ctx *Context, cancelled bool, reason string) error // The number for spawned workers that dequeue and execute jobs in parallel. // // Default: 2. Workers int // The maximum attempts to complete a task. Zero means that the jobs is // retried forever. The error retry field will take precedence to this // setting and allow retry beyond the configured maximum. // // Default: 0 MaxAttempts int // The rate at which a worker will request a job from the queue. // // Default: 100ms. Interval time.Duration // The minimal delay after a failed task is retried. // // Default: 1s. MinDelay time.Duration // The maximal delay after a failed task is retried. // // Default: 10m. MaxDelay time.Duration // The exponential increase of the delay after individual attempts. // // Default: 2. DelayFactor float64 // Time after which the context of a job is cancelled and the execution // should be stopped. Should be several minutes less than timeout to prevent // race conditions. // // Default: 5m. Lifetime time.Duration // The time after which a task can be dequeued again in case the worker was // unable to set its state. // // Default: 10m. Timeout time.Duration // Set to let the system enqueue a job periodically every given interval. // // Default: 0. Periodicity time.Duration // The blueprint of the job that is periodically enqueued. // // Default: Blueprint{Name: Task.Name}. PeriodicJob Blueprint }
Task describes work that is managed using a job queue.