Skip to content

Queue

@warlock.js/queue runs background work outside the request/response cycle — sending an invoice email, syncing inventory, generating a report — as durable jobs stored in Redis via BullMQ. A job survives a process restart, retries on failure with backoff, and can be picked up by any worker process that shares the same Redis and job definitions.

Redis is required. BullMQ has no other backend.

This is not the same as @warlock.js/core’s Queue class, which is an in-memory batcher inside one process (nothing stored, no retries, lost on exit). Reach for @warlock.js/queue whenever the work must survive a restart or be retried.

warlock.config.ts
import { defineConfig } from "@warlock.js/core";
import { defineJob, queueConnector } from "@warlock.js/queue";
export default defineConfig({
connectors: [queueConnector()],
});
// anywhere in app code
export const sendInvoice = defineJob({
name: "invoices.send",
attempts: 5,
backoff: { type: "exponential", delay: 2000 },
async handle(payload: { invoiceId: string }, ctx) {
await ctx.progress(50);
},
});
await sendInvoice.dispatch({ invoiceId: "42" }, { delay: "10m", priority: 1 });

The connector starts workers once your app code (and therefore every defineJob) has loaded, and drains active jobs on shutdown.