Skip to content

queueJob — enqueue a background job

Imported from the facade: import { queueJob } from "@/framework/facade.js".

Enqueues a job into a BullMQ queue with retry/backoff defaults, and returns the Job (or null when Redis is unavailable). See Events & Queue.

Signature

FunctionSignatureDescription
queueJob(job, data, options?) => Promise<Job/null>Enqueue a job with retry/backoff defaults

Options:

OptionTypeDefaultDescription
queuestring"default"Target queue name
delaynumber0Delay in seconds before the job is visible to workers
attemptsnumber3Maximum retries if the job fails
jobIdstringautoCustom ID for idempotency (duplicates prevented)
prioritynumberHigher number processed first
backoffobject{ type: "exponential", delay: 3000 }Retry strategy: "exponential" or "fixed"
removeOnCompletenumber1000Keep at most N completed jobs
removeOnFailnumber5000Keep at most N failed jobs

Use cases

Enqueue with options

ts
import { queueJob } from "@/framework/facade.js";

await queueJob("process-image", { path: "/tmp/photo.jpg" }, {
  queue: "images",
  delay: 30,                                  // seconds from now
  attempts: 5,                                // retry up to 5 times
  priority: 10,                               // higher = processed first
  jobId: "img-123",                           // custom ID — prevents duplicates
  backoff: { type: "fixed", delay: 5000 },    // 5s between retries
  removeOnComplete: 500,
  removeOnFail: 2000,
});

When Redis is off

ts
const job = await queueJob("process-image", { path });
if (job === null) { /* Redis unavailable — handle gracefully */ }

Notes

  • Requires Redis; returns null (never throws) when Redis is unavailable on the app side.
  • Default queue resources: attempts: 3, exponential backoff 3s, keep 1000 completed / 5000 failed — override per enqueue.
  • Handlers register with shouldQueue(job, queue, fn); the job name and queue name must match.

Released under the MIT License.