jobqueue

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0, MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueShutdown = errors.New("queue is shutdown")

ErrQueueShutdown means the queue is shutdown so the job could not be queued

Functions

This section is empty.

Types

type Handler

type Handler[Job any] func(ctx context.Context, j Job) error

Handler handles jobs of the given type

type JobQueue

type JobQueue[Job any] struct {
	// contains filtered or unexported fields
}

JobQueue is asyncronous queue for jobs, that can be processed in parallel by the job queue's handler

func NewJobQueue

func NewJobQueue[Job any](handler Handler[Job], opts ...Option) *JobQueue[Job]

NewJobQueue returns a new job queue that processes with the given handler

func (*JobQueue[Job]) Queue

func (p *JobQueue[Job]) Queue(ctx context.Context, j Job) error

Queue attempts to queue the job. It will fail if the queue is shutdown, or the passed context cancels before the job can be queued

func (*JobQueue[Job]) Shutdown

func (p *JobQueue[Job]) Shutdown(ctx context.Context) error

Shutdown shuts down the queue, returning when the whole queue is shutdown or the passed context cancels

func (*JobQueue[Job]) Startup

func (p *JobQueue[Job]) Startup()

Startup starts the queue in the background (returns immediately)

type Option

type Option func(*config)

Option modifies the config of a JobQueue

func WithBuffer

func WithBuffer(buffer int) Option

WithBuffer allows a set amount of jobs to be buffered even if all workers are busy

func WithConcurrency

func WithConcurrency(concurrency int) Option

WithConcurrency sets the number of workers that will process jobs in parallel

func WithErrorHandler

func WithErrorHandler(errorHandler func(error)) Option

WithErrorHandler uses the given error handler whenever a job errors while processing

func WithJobTimeout

func WithJobTimeout(jobTimeout time.Duration) Option

WithJobTimeout cancels the past into context to the job handler after the specified timeout

func WithShutdownTimeout

func WithShutdownTimeout(shutdownTimeout time.Duration) Option

WithShutdownTimeout sets the shutdown timeout. When the queue is shutdown, the context passed to all job handlers will cancel after the specified timeout

Jump to

Keyboard shortcuts

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