Bull Job Queue
A scalable and developer-ready background job queue system built on Bull and Redis. Supports retries, delays, dashboards, and REST control.
Overview
A robust, fault-tolerant job queue component for Express applications powered by Bull and Redis. Enables background processing, scheduled tasks, automatic retries, and includes a real-time web dashboard (Bull Board) for monitoring. Perfect for sending emails, processing uploads, caching, notifications, and other async workloads.
Installation
What This Does
Installs a complete Bull + Redis job queue system with REST endpoints, retry logic, and a Bull Board admin dashboard.
Files & Folders Created
| File / Path | Description |
|---|---|
| /src/config/queue.js | Configures Bull and Redis connection. |
| /src/routes/jobs.js | REST API routes for job management. |
| /src/services/jobService.js | Add, fetch, and retry jobs. |
| /src/config/dashboard.js | Bull Board web UI setup. |
| /.env.example | Redis connection and queue settings. |
Files to be modified
| File / Path | Description |
|---|---|
| server.js | Mounts /api/jobs and /admin/queues routes. |
| .env | Adds Redis and queue configuration. |
Configuration
# Redis Configuration REDIS_HOST=127.0.0.1 REDIS_PORT=6379 # Queue Settings QUEUE_NAME=background-jobs MAX_RETRIES=3 PORT=3001
Frontend Integration
Use this component with your frontend (Next.js or React) to enqueue background jobs like sending emails, generating reports, or processing uploads. You can also monitor job progress using the built-in Bull Board UI.
Adds a new job to the queue with optional delay or retries.
Retrieves the status and result of a specific job.
Retries all failed jobs currently in the queue.
Get queue statistics and job counts.
Example
1// app/jobs/EnqueueJob.jsx (Next.js example)
2'use client';
3import { useState } from 'react';
4
5export default function EnqueueJob() {
6 const [jobId, setJobId] = useState(null);
7 const [status, setStatus] = useState('');
8
9 async function enqueueEmailJob() {
10 setStatus('Submitting job...');
11 try {
12 const res = await fetch('/api/jobs/add', {
13 method: 'POST',
14 headers: { 'Content-Type': 'application/json' },
15 body: JSON.stringify({ task: 'sendEmail', email: 'user@example.com' }),
16 });
17 const data = await res.json();
18 if (data.success) {
19 setJobId(data.jobId);
20 setStatus('✅ Job queued successfully!');
21 } else {
22 setStatus('⚠️ Failed to queue job');
23 }
24 } catch (err) {
25 setStatus('❌ Error connecting to job queue');
26 }
27 }
28
29 async function checkStatus() {
30 if (!jobId) return;
31 const res = await fetch('/api/jobs/status/' + jobId);
32 const data = await res.json();
33 alert(JSON.stringify(data.status, null, 2));
34 }
35
36 return (
37 <div className="p-4 border border-white/10 rounded-lg bg-black/30">
38 <button
39 onClick={enqueueEmailJob}
40 className="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded font-medium"
41 >
42 Queue Email Job
43 </button>
44
45 {jobId && (
46 <button
47 onClick={checkStatus}
48 className="ml-3 bg-emerald-600 hover:bg-emerald-700 text-white px-4 py-2 rounded font-medium"
49 >
50 Check Job Status
51 </button>
52 )}
53
54 <p className="text-sm text-gray-400 mt-3">{status}</p>
55 <p className="text-xs text-gray-500 mt-1">
56 🔍 Monitor queue: <a href="/admin/queues" className="underline">Bull Board Dashboard</a>
57 </p>
58 </div>
59 );
60}Usage
1// Enqueue and monitor background jobs
2const { addJob, getJobStatus } = require('./src/services/jobService');
3
4// Add new job
5const job = await addJob({ task: 'emailReport', to: 'user@example.com' });
6
7// Check status
8const status = await getJobStatus(job.id);
9console.log(status);