Skip to main content

Module worker

Module worker 

Source
Expand description

The worker loop: reserve, run, and then delete, retry, or bury.

What queue:work runs. A worker is deliberately dull — it owns no state beyond its options, so N of them against one queue is the same code run N times, and a worker that dies mid-job leaves the job recoverable rather than lost.

Structs§

Shutdown
A shutdown signal shared by every worker in a pool.
Worker
One worker. Cloning is cheap and gives a second worker on the same queue.
WorkerOptions
How a worker behaves.
WorkerStats
A tally of what a worker did, returned when it stops.

Enums§

Outcome
What happened to one job.

Constants§

DEFAULT_BACKOFF_CAP
The ceiling on exponential backoff. Without one, a job on its fifteenth attempt would be scheduled a year out and never seen again.
DEFAULT_POLL_INTERVAL
How long a worker waits before asking an empty queue again.

Functions§

backoff
How long to wait before the next attempt.
outcome_to_json
A convenience for a dashboard: the worker events as JSON.
run_pool
Run count copies of a worker concurrently, all watching one shutdown signal, and return their combined tally once every one has stopped.