Enqueue options
Priority, delay, idempotency, metadata, and routing at enqueue time.
Priority, delay, idempotency, metadata, and routing at enqueue time.
The third argument to enqueue sets per-job options:
queue.enqueue("send_email", [user], {
queue: "emails",
priority: 5,
delayMs: 30_000,
uniqueKey: `welcome:${user.id}`,
metadata: "source=signup",
notes: { campaign: "welcome", attempt: 1 },
});| Option | Description |
|---|---|
queue | The named queue to route to (default "default") — see Queues & Priority. |
priority | Higher dequeues first within a queue. |
maxRetries | Override the task's retry budget for this job. |
timeoutMs | Override the per-attempt timeout for this job. |
delayMs | Delay first execution by this many ms (scheduled run). |
uniqueKey | Idempotency key — a duplicate enqueue is a no-op while the first job is pending/running. |
metadata | Free-form string stored with the job (surfaces on the dashboard / inspection). |
notes | Structured annotations — a JSON object, ≤15 fields and ≤4 KiB encoded. |
namespace | Tenant/environment isolation — a worker only claims jobs whose namespace exactly matches its own (unset by default). Orthogonal to queue: two jobs can share a queue name but sit in different namespaces, invisible to each other's workers. |
Coming from BullMQ? BullMQ's
add(name, data, opts)third argument maps field-for-field:opts.delay→delayMs,opts.priority→priority(inverted direction — see queues), and an explicit customopts.jobId(BullMQ's usual dedup trick) →uniqueKey. flexiq'suniqueKeydedup is automatic and scoped to "while the first job is pending/running" — it frees up once that job finishes, rather than permanently reserving the key.
uniqueKey dedupes concurrent producers — only one job runs for a given key
while an earlier one is still pending or running. See
idempotency.
delayMs schedules the first attempt in the future; the scheduler picks it up
when due. For recurring schedules use periodic tasks.
notes attaches a small, structured object to the job — distinct from the
free-form metadata string. It is validated (≤15 top-level fields, ≤4 KiB
encoded) and rendered on the dashboard. It survives dead-letter and replay.
queue.enqueue("import", [fileId], { notes: { rows: 1200, source: "s3" } });enqueueMany inserts many jobs of one task in a single storage round-trip. Each
entry has its own args and options; it returns the ids in input order.
const ids = queue.enqueueMany("resize", [
{ args: ["a.png"], options: { priority: 5 } },
{ args: ["b.png"] },
]);Entries carrying a uniqueKey dedup exactly like enqueue — a key with a
pending or running job yields that job's id rather than a new row. A batch with
no keys at all takes the plain bulk-insert fast path.