Documentation ¶
Index ¶
Constants ¶
const ( // StatusDone indicates the Job is successfully finished. StatusDone = "DONE" // StatusPanic indicates there was a panic during job-execution. // This is a terminal status and will NOT be retried. StatusPanic = "PANIC" // StatusFailed indicates job failed to succeed even after retries. // This is a terminal status and will NOT be retried. StatusFailed = "FAILED" // StatusPending indicates at-least 1 attempt is still pending. StatusPending = "PENDING" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type DequeueFn ¶
DequeueFn is invoked by the JobQueue for ready jobs. It is responsible for handling a ready job and returning the updated version after the attempt.
type Job ¶
type Job struct { // Specification of the job. ID string `json:"id"` Kind string `json:"kind"` RunAt time.Time `json:"run_at"` Payload []byte `json:"payload"` // Internal metadata. Status string `json:"status"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` // Execution information. Result []byte `json:"result,omitempty"` AttemptsDone int64 `json:"attempts_done"` LastAttemptAt time.Time `json:"last_attempt_at,omitempty"` LastError string `json:"last_error,omitempty"` }
Job represents the specification for async processing and also maintains the progress so far.
type JobFn ¶
JobFn is invoked by the Worker for ready jobs. If it returns no error, job will be marked with StatusDone. If it returns RetryableError, the job will remain in StatusPending and will be enqueued for retry. If it returns any other error, job will be marked as StatusFailed. In case if a panic occurs, job will be marked as StatusPanic.
type JobQueue ¶
type JobQueue interface { // Enqueue all jobs. Enqueue must ensure all-or-nothing behaviour. // Jobs with zero-value or historical value for ReadyAt must be // executed immediately. Enqueue(ctx context.Context, jobs ...Job) error // Dequeue one job having one of the given kinds and invoke `fn`. // The job should be 'locked' until `fn` returns. Refer DequeueFn. Dequeue(ctx context.Context, kinds []string, fn DequeueFn) error }
JobQueue represents a special queue that holds jobs and releases them via Dequeue() only after their RunAt time.
type RetryableError ¶
RetryableError can be returned by a JobFn to instruct the worker to attempt retry after time specified by the RetryAfter field. RetryAfter can have min of 5 seconds.
func (*RetryableError) Error ¶
func (re *RetryableError) Error() string
func (RetryableError) WithCause ¶
func (re RetryableError) WithCause(err error) *RetryableError
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker provides asynchronous job processing using a job-queue.