handler

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func Exec

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

Exec executes handler functions with a concrete timeout

Types

type Func

type Func func(ctx context.Context, job model.QueueJob) error

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

type Handler

type Handler struct {
	Queue         string
	Concurrency   int
	CheckInterval time.Duration
	JobTimeout    time.Duration
	Handle        Func
}

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 (*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 Queue handlers to process jobs concurrently the default concurrency is the number of (v)CPUs on the machine running Queue

func JobTimeout

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

Jump to

Keyboard shortcuts

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