Bull Job Queue

4.16.5 · maintenance · verified Sat Apr 18

Bull is a battle-tested, Redis-based job queue library for Node.js, designed for reliability and atomic operations. It provides a robust system for managing background jobs, handling retries, delays, and concurrent processing. The current stable version is 4.16.5. While regular bug fixes are released, Bull is currently in maintenance mode; new features are primarily being developed in BullMQ, a modern TypeScript rewrite.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a Bull queue, adding a job to it, and setting up a worker to process jobs from that queue. It also shows a basic event listener for job completion.

import { Queue } from 'bull';

const REDIS_URL = process.env.REDIS_URL ?? 'redis://127.0.0.1:6379';
const myQueue = new Queue('my-first-queue', REDIS_URL);

// Add a job to the queue
async function addJob() {
  const job = await myQueue.add({ foo: 'bar' });
  console.log(`Job ${job.id} added.`);
}

// Process jobs from the queue
myQueue.process(async (job) => {
  console.log(`Processing job ${job.id} with data:`, job.data);
  // Simulate async work
  await new Promise(resolve => setTimeout(resolve, 1000));
  console.log(`Job ${job.id} completed.`);
  return { status: 'success', processedAt: new Date() };
});

// Listen for global completed event (optional)
myQueue.on('global:completed', (jobId, result) => {
  console.log(`Job ${jobId} completed globally with result:`, JSON.parse(result));
});

// Call addJob to demonstrate
addJob().catch(console.error);

view raw JSON →