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 or in a local SQLite file without Redis. Both survive restarts and retry on failure. Use the memory driver for tests that execute real handlers.

See Local and memory queues for backend selection, leases, crash recovery, and cancellation on Node >= 22.15.

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.