Skip to content

Enqueueing Jobs

const { jobId, getStatus } = await jobClient.myJob.enqueue(input, options?);

input is validated against the job’s Zod schema at enqueue time. If validation fails, it throws.

.enqueue() returns an EnqueueResult:

FieldTypeDescription
jobIdstringUnique job ID
getStatus() => Promise<JobStatusResponse>Fetches the current status from the API

All optional. Per-job defaults can be set via the defaults field in job(). Options passed to .enqueue() override defaults.

OptionTypeDescription
delaystring | numberDelay before running. Strings: '5s', '5m', '1h', '2d'. Numbers: milliseconds.
retriesnumberNumber of retry attempts on failure.
backoff'linear' | 'exponential'Backoff strategy for retries.
backoffDelaynumberBase delay between retries in ms (default: 1000).
concurrencynumberMax concurrent executions of this job type per worker.
await jobClient.sendEmail.enqueue(
{ to: "user@example.com", subject: "Hi", body: "Hello" },
{
delay: "5m",
retries: 5,
backoff: "exponential",
backoffDelay: 2000,
},
);

Call getStatus() to poll for a job’s current state. Each call makes a fresh request to the Queuebase API.

const { jobId, getStatus } = await jobClient.generateExport.enqueue({
type: "CSV",
});
const poll = setInterval(async () => {
const status = await getStatus();
if (status.status === "completed") {
clearInterval(poll);
const downloadUrl = (status.result as { url: string }).url;
// show download link
}
if (status.status === "failed") {
clearInterval(poll);
// show error: status.error
}
}, 1000);
FieldTypeDescription
publicIdstringPublic job ID
namestringJob name (the key from the router)
status'pending' | 'running' | 'completed' | 'failed' | 'cancelled'Current status
attemptnumberCurrent attempt number
maxAttemptsnumberMaximum attempts allowed
createdAtstringISO timestamp
startedAtstring | nullISO timestamp or null
completedAtstring | nullISO timestamp or null
resultunknownReturn value from the handler on success
errorstring | nullError message on failure