Enqueueing Jobs
Enqueue
Section titled “Enqueue”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 result
Section titled “Enqueue result”.enqueue() returns an EnqueueResult:
| Field | Type | Description |
|---|---|---|
jobId | string | Unique job ID |
getStatus | () => Promise<JobStatusResponse> | Fetches the current status from the API |
Options
Section titled “Options”All optional. Per-job defaults can be set via the defaults field in job(). Options passed to .enqueue() override defaults.
| Option | Type | Description |
|---|---|---|
delay | string | number | Delay before running. Strings: '5s', '5m', '1h', '2d'. Numbers: milliseconds. |
retries | number | Number of retry attempts on failure. |
backoff | 'linear' | 'exponential' | Backoff strategy for retries. |
backoffDelay | number | Base delay between retries in ms (default: 1000). |
concurrency | number | Max concurrent executions of this job type per worker. |
Example with options
Section titled “Example with options”await jobClient.sendEmail.enqueue( { to: "user@example.com", subject: "Hi", body: "Hello" }, { delay: "5m", retries: 5, backoff: "exponential", backoffDelay: 2000, },);Checking job status
Section titled “Checking job status”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);JobStatusResponse
Section titled “JobStatusResponse”| Field | Type | Description |
|---|---|---|
publicId | string | Public job ID |
name | string | Job name (the key from the router) |
status | 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | Current status |
attempt | number | Current attempt number |
maxAttempts | number | Maximum attempts allowed |
createdAt | string | ISO timestamp |
startedAt | string | null | ISO timestamp or null |
completedAt | string | null | ISO timestamp or null |
result | unknown | Return value from the handler on success |
error | string | null | Error message on failure |