Skip to content
Get started
Get started
Worker: Process Jobs from a Bun Queue
View Markdown
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 (until the job’s attempts total executions are used up; the default 3 means 1 run + 2 retries) and then moved to the dead letter queue, a holding area for jobs that keep failing.

Both TypeScript packages pass { signal } as the optional second processor argument:

const worker = new Worker('downloads', async (job, context) => {
const response = await fetch(job.data.url, { signal: context?.signal });
return await response.arrayBuffer();
});

Per-job timeout and worker.cancelJob() abort this signal. Promise processors remain cooperative: code that ignores the signal continues running, although a late outcome cannot overwrite a broker timeout. The processor may also return a structural Observable; bunqueue stores its final emission, fails on error or empty completion, and unsubscribes on abort. No RxJS dependency is required.

For BullMQ Pro-oriented imports, WorkerPro is an alias of this same Worker; QueuePro, QueueEventsPro, and the JobPro<T> type are exported alongside it. The aliases do not create a second implementation or enable telemetry.

GuideWhat it covers
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