Skip to main content

Overview

Workers are the workhorses of BullMQ that pick up jobs from queues and process them. Each worker runs a processor function that handles the job’s business logic.
Workers automatically start processing jobs when instantiated. Set autorun: false to control when processing begins.

Processor Function

The processor function is called for each job and must return a promise:

Basic Processor

Processor with Progress

Report progress during long-running jobs:

Processor with Cancellation Support

Handle job cancellation gracefully:

Worker Options

WorkerOptions Interface

Concurrency

Process multiple jobs simultaneously:
Each worker can process multiple jobs concurrently. Scale horizontally by running multiple worker instances.

Worker Events

Job Lifecycle Events

Worker State Events

Always add an ‘error’ listener to prevent unhandled exceptions that could crash your worker.

Stalled Jobs

Pausing and Resuming

Pause only this worker instance:

Rate Limiting

Worker-Level Rate Limiting

Manual Rate Limiting

Manually trigger rate limiting from within a processor:

Graceful Shutdown

Properly close workers to avoid job loss:

Sandboxed Processors

Run processors in separate processes or worker threads:

Stalled Jobs

BullMQ automatically recovers stalled jobs:
A job is considered stalled when its lock expires without being renewed. This usually indicates a crashed worker or hung processor.

Manual Job Fetching

Fetch jobs manually for advanced use cases:

TypeScript Support

Type-safe workers with generics:

Best Practices

Handle Errors

Always add error listeners and handle exceptions gracefully in your processor.

Use Concurrency Wisely

Set concurrency based on your workload. CPU-bound tasks should use lower concurrency.

Monitor Progress

Update progress for long-running jobs to provide visibility.

Graceful Shutdown

Always close workers properly to avoid losing in-progress jobs.

Set Lock Duration

Configure lockDuration based on expected job duration plus buffer time.

Clean Up Resources

Use removeOnComplete and removeOnFail to prevent Redis memory bloat.

Next Steps

Jobs

Learn about job lifecycle and manipulation

Events

Monitor worker activity with events

Queues

Understand queue operations