workers

package
v0.0.0-...-c07ec26 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultWorker

type DefaultWorker struct{}

func (DefaultWorker) Execute

func (f DefaultWorker) Execute(ctx context.Context, job jobs.Job) (interface{}, error)

Execute runs the worker function for the given job.

func (DefaultWorker) OnFailure

func (f DefaultWorker) OnFailure(ctx context.Context, job jobs.Job) error

OnFailure runs the on failure callback for the given job.

type Handler

type Handler interface {
	Handle(ctx context.Context, job jobs.Job) error
}

Handler handles job execution, errors and results.

type PoolOptionFunc

type PoolOptionFunc func(p *WorkerPool) *WorkerPool

func WithAdminUI

func WithAdminUI(addr string) PoolOptionFunc

func WithErrorHandler

func WithErrorHandler(f func(error)) PoolOptionFunc

func WithGracefulShutdown

func WithGracefulShutdown() PoolOptionFunc

func WithReaperInterval

func WithReaperInterval(interval time.Duration) PoolOptionFunc

func WithSchedulerInterval

func WithSchedulerInterval(interval time.Duration) PoolOptionFunc

type Queue

type Queue interface {
	Poll(ctx context.Context) (jobs.Job, error)
	RequeueTimedOutJobs(ctx context.Context, timeout time.Duration) error
}

Queue is a queue of jobs.

type Spawner

type Spawner interface {
	Spawn(runner)
	Wait()
	Shutdown()
	Done() <-chan struct{}
}

type Worker

type Worker interface {
	Execute(ctx context.Context, job jobs.Job) (interface{}, error)
	OnFailure(ctx context.Context, job jobs.Job) error
}

Worker is the interface that must be implemented by workers.

type WorkerFunc

type WorkerFunc func(ctx context.Context, job jobs.Job) (interface{}, error)

WorkerFunc is a function that can be used as a worker.

type WorkerOptionFunc

type WorkerOptionFunc func(workerConfig) workerConfig

func WithInstances

func WithInstances(i int) WorkerOptionFunc

func WithTimeout

func WithTimeout(d time.Duration) WorkerOptionFunc

type WorkerPool

type WorkerPool struct {
	// contains filtered or unexported fields
}

func NewWorkerPool

func NewWorkerPool(database *sql.DB, opts ...PoolOptionFunc) *WorkerPool

func (WorkerPool) RegisterWorker

func (r WorkerPool) RegisterWorker(queueName string, worker Worker, opts ...WorkerOptionFunc)

RegisterWorker registers a worker with the given name.

func (WorkerPool) RegisterWorkerFunc

func (r WorkerPool) RegisterWorkerFunc(queueName string, worker WorkerFunc, opts ...WorkerOptionFunc)

RegisterWorkerFunc registers a worker function with the given queue name.

func (*WorkerPool) Start

func (w *WorkerPool) Start() error

Start the WorkerPool

func (WorkerPool) Stop

func (w WorkerPool) Stop()

Stop the WorkerPool

Jump to

Keyboard shortcuts

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