A Redis-backed job queue for Node.js. Like BullMQ, but smaller and lighter.
npm install @chamanbravo/jabyimport Redis from "ioredis";
import { Queue, Worker } from "@chamanbravo/jaby";
const client = new Redis();
const queue = new Queue("emails", client);
await queue.add({
data: { to: "coder@himaligoat.com", subject: "Add me in your codebase" },
});
// Create a worker
const worker = new Worker(
queue,
async (job) => {
await sendEmail(job.data);
},
client,
);// Run this in 10 seconds.
await queue.add({
data: { message: "think about it" },
opts: { delay: 10_000 },
});await queue.add({
data: { url: "https://flaky-api.example.com" },
opts: {
attempts: 5,
backoff: { type: "exponential", delay: 1000 },
// will retry at 2s, 4s, 8s, 16s before giving up and moving on with its life
},
});queue
.on("completed", ({ jobId }) => console.log(`${jobId} done`))
.on("failed", ({ jobId, reason }) =>
console.error(`${jobId} exploded: ${reason}`),
)
.on("retrying", ({ jobId, attempt }) =>
console.warn(`${jobId} trying again (attempt ${attempt})`),
);Events are published over Redis pub/sub, so multiple processes all see them.
// Process multiple jobs at once
const worker = new Worker(queue, processor, client, { concurrency: 5 });| Key | What's in it |
|---|---|
queue:<name>:<id> |
Job hash |
queue:<name>:waiting |
Jobs ready to go |
queue:<name>:delayed |
Jobs waiting for their moment |
queue:<name>:active |
Jobs currently being worked on |
queue:<name>:completed |
Jobs that made it |
queue:<name>:failed |
Jobs that did not |