A robust, asynchronous job queue system built with Node.js, Express, BullMQ, and Redis.
- Express API: Exposes endpoints to easily enqueue new jobs.
- BullMQ: Powerful Redis-based queue for reliable background job processing.
- Retry Mechanism: Exponential backoff configured for failed jobs (retries 3 times with a 5-second initial delay).
- TypeScript: Strictly typed backend code.
Before running the project, make sure you have the following installed:
- Node.js (v18+ recommended)
- Redis server running on
localhost:6379(default BullMQ configuration)
- Clone the repository and navigate to the project directory:
cd job-q-sys - Install the dependencies:
npm install
- Set up your environment variables by copying
.env.exampleto.env(if applicable), ensuring you configure the appropriate values likePORT=3000.
The application is split into two components: the API server and the background worker. You'll need to run both concurrently in separate terminal windows.
This process handles incoming HTTP requests and pushes jobs to the Redis queue.
npm run dev2The server will start listening on port 3000 (or the port defined in your .env).
This process listens to the Redis queue and executes the job logic.
npm run dev1The project includes an OpenAPI specification file (openapi.yaml) detailing the available endpoints.
Adds a new job to the queue.
Request Body (JSON):
{
"type": "email",
"payload": {
"to": "test@example.com",
"subject": "Hello!"
}
}Response (JSON):
{
"message": "Job added to queue",
"jobId": "1"
}- A client sends a
POST /jobrequest to the Express server. - The server creates a new job using BullMQ (
jobQueue.add()) with the providedtypeandpayload, configured for 3 attempts and an exponential backoff of 5000ms. - The BullMQ Worker picks up the job from Redis.
- The worker processes the job based on its
type(e.g., iftype === "email", it currently throws an error to demonstrate the failure/retry mechanism, otherwise it completes after a 2-second delay). - The worker logs the completion or failure status.