Defining Jobs
Use job() to define a job and createJobRouter() to group them into a router.
import { createJobRouter, job } from "@queuebase/nextjs"; // or @queuebase/nodeimport { z } from "zod";
export const jobs = createJobRouter({ myJob: job({ input: z.object({ /* Zod schema */ }), handler: async (ctx) => { /* returns output */ }, defaults: { /* optional EnqueueOptions */ }, }),});Handler context
Section titled “Handler context”The handler receives a JobContext object:
| Field | Type | Description |
|---|---|---|
input | Inferred from Zod schema | Validated input data |
jobId | string | Unique job ID |
attempt | number | Current attempt (1-indexed) |
maxAttempts | number | Maximum attempts allowed |
handler: async ({ input, jobId, attempt, maxAttempts }) => { console.log(`Job ${jobId}, attempt ${attempt}/${maxAttempts}`); // use input (fully typed from your Zod schema) return { success: true };}Defaults
Section titled “Defaults”You can set default enqueue options per job via the defaults field. These are merged with (and overridden by) options passed to .enqueue().
sendEmail: job({ input: z.object({ to: z.string().email() }), handler: async ({ input }) => { // ... return { sent: true }; }, defaults: { retries: 3, backoff: "exponential", backoffDelay: 2000, },}),See Enqueueing Jobs for the full list of options.