jobqueue

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPermanentError

func NewPermanentError(err error) error

NewPermanentError creates an error that will prevent the job queue from retrying the job

func WithOnFailure

func WithOnFailure[T any](onFailure worker.OnFailureFn[T]) worker.JobOption[T]

WithOnFailure sets a callback to be invoked only when the job fails after max retries The JobQueue only supports a single OnFailure callback for a job, multiple OnFailure options must not be provided.

Types

type Config

type Config struct {
	Logger      logger.StandardLogger
	MaxWorkers  uint
	MaxRetries  uint
	MaxTimeout  time.Duration
	ExtendDelay time.Duration
	// contains filtered or unexported fields
}

type DedupQueueConfig

type DedupQueueConfig struct {
	DedupeEnabled     *bool
	BlockRepeatsOnDLQ *bool
	HashFunc          dedup.HashFunc
}

type JobQueue

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

func New

func New[T any](name string, db *sql.DB, ser serializer.Serializer[T], opts ...Option) (*JobQueue[T], error)

func (*JobQueue[T]) Enqueue

func (j *JobQueue[T]) Enqueue(ctx context.Context, name string, msg T) error

func (*JobQueue[T]) Register

func (j *JobQueue[T]) Register(name string, fn func(context.Context, T) error, opts ...worker.JobOption[T]) error

func (*JobQueue[T]) RegisterHandler

func (j *JobQueue[T]) RegisterHandler(handler TaskHandler[T], opts ...worker.JobOption[T]) error

func (*JobQueue[T]) Start

func (j *JobQueue[T]) Start(ctx context.Context) error

func (*JobQueue[T]) Stop

func (j *JobQueue[T]) Stop(ctx context.Context) error

type Option

type Option func(c *Config) error

func WithDedupQueue

func WithDedupQueue(cfg *DedupQueueConfig) Option

func WithExtendDelay

func WithExtendDelay(extendDelay time.Duration) Option

func WithLogger

func WithLogger(l logger.StandardLogger) Option

func WithMaxRetries

func WithMaxRetries(maxRetries uint) Option

func WithMaxTimeout

func WithMaxTimeout(maxTimeout time.Duration) Option

func WithMaxWorkers

func WithMaxWorkers(maxWorkers uint) Option

func WithQueueProvider

func WithQueueProvider(provider QueueProvider) Option

type QueueProvider

type QueueProvider struct {
	Setup func(context.Context, *sql.DB) error
	New   func(name string, db *sql.DB, opts QueueProviderOpts) (queue.Interface, error)
}

type QueueProviderOpts

type QueueProviderOpts struct {
	MaxReceive int
	Timeout    time.Duration
	Logger     logger.StandardLogger
}

type Service

type Service[T any] interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	Register(name string, fn func(context.Context, T) error, opts ...worker.JobOption[T]) error
	RegisterHandler(handler TaskHandler[T], opts ...worker.JobOption[T]) error
	Enqueue(ctx context.Context, name string, msg T) error
}

type TaskHandler

type TaskHandler[T any] interface {
	Handle(ctx context.Context, payload T) error
	Name() string
}

Directories

Path Synopsis
internal
sql
Package jobqueue provides a Worker which can run registered job [Func]s by name, when a message for it is received on the underlying queue.
Package jobqueue provides a Worker which can run registered job [Func]s by name, when a message for it is received on the underlying queue.

Jump to

Keyboard shortcuts

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