Skip to content
Get started
Get started
Worker: Process Jobs from a Bun Queue
guide · worker

Pull, process, ack.

A worker is a loop you do not have to write. It asks the queue for work, runs your function, reports the outcome, and keeps the job alive while it runs.

Give the Worker a queue name and a processor. Whatever the processor returns becomes the job result; whatever it throws becomes a failed attempt.

import { Worker } from 'bunqueue/client';
const worker = new Worker('my-queue', async (job) => {
// Process the job; the return value is stored as the job's result
return { success: true };
}, { embedded: true });

The Bun, TypeScript, and Python workers start polling immediately (autorun); the PHP, Go, Rust, and Elixir workers start when you call their run function. If your processor throws, the job is retried automatically (up to the job’s attempts, default 3) and then moved to the dead letter queue, a holding area for jobs that keep failing.

Worker Concurrency and Batch PullingRun jobs in parallel and pull them in batches
The Job Object Inside a Worker ProcessorEverything the processor receives and can do
Worker Eventscompleted, failed, stalled and the rest
Worker Error Handling, Retries and BackoffRetries, backoff, timeouts and giving up
Worker LifecyclePause, resume and shut down without losing work
Heartbeats, Stall Detection and Lock OwnershipHeartbeats, stall recovery and lock ownership
SandboxedWorkerExperimental isolation for CPU-heavy handlers
WorkerOptions ReferenceEvery WorkerOptions field, with defaults