embed

package
v0.0.0-...-3352087 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package embed provides an embeddable runtime for sqlq workers.

It enables users to implement a long-living, background service that can either be embedded in the same application or packaged as a separate executable.

Index

Constants

This section is empty.

Variables

View Source
var ErrWorkerClosed = errors.New("sqlq: worker closed")

ErrWorkerClosed indicates that the worker has already been closed

View Source
var ErrWorkerRunning = errors.New("sqlq: worker running")

ErrWorkerRunning indicated that the worker has already started running, and no further changes can be made

Functions

This section is empty.

Types

type Worker

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

Worker is the main service where you'd register handlers for different job types, and it'd (at configured time intervals) pull jobs from the queue to execute.

A worker also owns and manages lifecycle of other critical services, like, reaper and janitor. It provides an execution environment for a job, and manages critical things such as log shipping, keep-alive etc.

func NewWorker

func NewWorker(db *sql.DB, config WorkerConfig) (*Worker, error)

NewWorker creates a new instance of worker, configures it using the provided options and return it.

func (*Worker) Register

func (worker *Worker) Register(typeName string, handler sqlq.Handler) error

Register registers the given function as the handler for given job type.

func (*Worker) Shutdown

func (worker *Worker) Shutdown(timeout time.Duration) error

Shutdown attempts to gracefully shut the server down, waiting for timeout before forcefully terminating tasks. After Shutdown() is called, no new tasks are fetched from the queue to be processed.

func (*Worker) Start

func (worker *Worker) Start() error

Start starts background execution of worker. It schedules all background goroutines and other services to run. It starts pulling job from the configured queues and starts processing them.

type WorkerConfig

type WorkerConfig struct {
	// Maximum number of concurrent processing of tasks this worker should handle.
	//
	// If set to a zero or negative value, NewWorker will overwrite the value
	// to the number of CPUs usable by the current process.
	Concurrency int

	// List of queues from where the worker will retrieve jobs.
	// User must provide one or more queues to watch.
	Queues []sqlq.Queue
}

Jump to

Keyboard shortcuts

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