handler

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultHandlerTimeout = 30 * time.Second
)

Variables

View Source
var (
	ErrContextHasNoJob     = errors.New("context has no Job")
	ErrNoHandlerForQueue   = errors.New("no handler for queue")
	ErrNoProcessorForQueue = errors.New("no processor configured for queue")
)

Functions

func DefaultRecoveryCallback added in v0.65.0

func DefaultRecoveryCallback(_ context.Context, _ error) (err error)

DefaultRecoveryCallback is the function that gets called by default when handlers panic

func Exec

func Exec(ctx context.Context, handler Handler) (err error)

Exec executes handler functions with a concrete timeout

Types

type Func

type Func func(ctx context.Context) error

Func is a function that Handlers execute for every Job on a queue

type Handler

type Handler struct {
	Handle          Func
	Concurrency     int
	JobTimeout      time.Duration
	QueueCapacity   int64
	Queue           string
	RecoverCallback RecoveryCallback // function called when fatal handler errors occur
}

Handler handles jobs on a queue

func New

func New(queue string, f Func, opts ...Option) (h Handler)

New creates new queue handlers for specific queues. This function is to be usued to create new Handlers for non-periodic jobs (most jobs). Use NewPeriodic to initialize handlers for periodic jobs.

func NewPeriodic added in v0.27.0

func NewPeriodic(f Func, opts ...Option) (h Handler)

NewPeriodic creates new queue handlers for periodic jobs. Use New to initialize handlers for non-periodic jobs.

func (*Handler) WithOptions

func (h *Handler) WithOptions(opts ...Option)

WithOptions sets one or more options on handler

type Option

type Option func(w *Handler)

Option is function that sets optional configuration for Handlers

func Concurrency

func Concurrency(c int) Option

Concurrency configures Neoq handlers to process jobs concurrently the default concurrency is the number of (v)CPUs on the machine running Neoq

func JobTimeout added in v0.8.0

func JobTimeout(d time.Duration) Option

JobTimeout configures handlers with a time deadline for every executed job The timeout is the amount of time that can be spent executing the handler's Func when a timeout is exceeded, the job fails and enters its retry phase

func MaxQueueCapacity

func MaxQueueCapacity(capacity int64) Option

MaxQueueCapacity configures Handlers to enforce a maximum capacity on the queues that it handles queues that have reached capacity cause Enqueue() to block until the queue is below capacity

func Queue added in v0.27.0

func Queue(queue string) Option

Queue configures the name of the queue that the handler runs on

func RecoverCallback added in v0.65.0

func RecoverCallback(f RecoveryCallback) Option

RecoverCallback configures the handler with a recovery function to be called when fatal errors occur in Handlers

type RecoveryCallback added in v0.65.0

type RecoveryCallback func(ctx context.Context, err error) (erro error)

RecoveryCallback is a function to be called when fatal errors/panics occur in Handlers

Jump to

Keyboard shortcuts

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