ReadonlyclosingTruthy once IQueueBackend.close has begun (resolves when the close completes). Used by the worker to decide whether it is still safe to issue datastore operations (e.g. completing the current job) while the higher-level instance is shutting down.
ReadonlykeysThe map of named sub-keys/identifiers for the queue. For Redis these are the concrete Redis keys; backends that don't address jobs by key may return an empty map.
ReadonlyminimumSmallest meaningful block timeout (in seconds) supported by the backend's
blocking primitive. Used by workers to bound waitForJob.
ReadonlyqualifiedThe queue's fully-qualified name (the cross-backend logical identifier used
e.g. as a flow parent reference). Redis: "<prefix>:<queue>".
Atomically inserts a flow (tree) of jobs that may span multiple queues,
returning one [error, idOrCode] tuple per entry, in the same order they
were provided. Each entry is self-describing (it carries its own queue
prefix/queueName), so the operation is not bound to a single queue.
For the Redis adapter this is a single MULTI; a SQL backend would use a
single transaction.
Adds a single job to the queue, routing it to the correct initial state (wait / delayed / prioritized / waiting-children) based on its options.
The backend uses its own connection — callers never pass one in.
OptionalparentKeyOpts: ParentKeyOptsAdds many jobs to the queue in a single, efficient operation.
How the insert is batched (a Redis pipeline, a single multi-row SQL
INSERT, a transaction, …) is entirely an implementation detail of the
backend; the contract only requires that all jobs are added and their ids
returned in order.
The generated ids, in the same order as entries.
Registers a job scheduler and enqueues its next delayed iteration.
Two job-option bags are involved, with deliberately different roles:
templateOpts — the scheduler's template options, stored once and
reused as the basis for every future iteration produced by the scheduler.delayedJobOpts — the fully-resolved options for the single delayed
job created right now: the template plus this iteration's jobId,
delay, repeat.offset/count, etc.OptionalproducerId: stringA tuple of [jobId, delay] for the next iteration.
Appends a row to a job's log, optionally trimming old entries.
OptionalkeepLogs: numberThe total number of log entries.
Changes the delay of a delayed job.
Changes the priority (and optionally lifo) of a waiting job.
Optionalpriority: numberOptionallifo: booleanRemoves jobs in a given state that are older than timestamp.
Optionallimit: numberThe ids of the removed jobs.
Clears a job's logs, optionally keeping the most recent keepLogs rows.
OptionalkeepLogs: numberBuilds the connection client name (used for setName and worker/queue
discovery). Redis: "<prefix>:<base64(queue)><suffix>". Backends without a
client-name concept may return any stable string.
Optionalsuffix: stringCloses the backend and its underlying connection(s), waiting for any in-flight work to settle.
Optionalforce: boolean
When true, forcibly tears down the connection(s) without
waiting for in-flight (e.g. blocking) commands to finish.
Unconditionally deletes a deduplication key.
The number of keys removed.
Forcibly disconnects the backend's underlying connection(s).
Interrupts the backend's in-flight blocking wait (so a worker can stop or recover). No-op for backends without a dedicated blocking connection.
Optionalwait: booleanRemoves waiting (and optionally delayed) jobs from the queue.
Extends the lock of a single active job.
Extends the lock of several active jobs at once.
The ids of the jobs whose lock could not be extended.
Returns a sibling backend bound to a different queue (by name) that shares this backend's underlying connection(s).
This is used by FlowProducer, which spans multiple queues over a single connection: every node in a flow needs datastore operations scoped to its own queue, but they must all reuse the same connection. The returned backend has an independent identity (its operations target the given queue) but does not own the connection, so closing it is a no-op on the shared connection.
The queue the sibling backend should operate on.
Optionalprefix: string
Optional key prefix for the target queue. Flows may span queues under different prefixes, so when omitted the backend's own prefix is used.
Returns the raw worker/client list(s) for the queue's datastore. For the
Redis adapter this is CLIENT LIST (one string per cluster node, or a
single string otherwise). Backends with no notion of connected clients
may return an empty array.
Returns the job id currently holding the given deduplication key, if any.
Returns a job's children dependencies (processed/unprocessed/ignored/failed).
Returns the raw ignored-children failures map (child key → reason).
Returns the stored data for a job, or undefined if it is missing.
Returns the raw stored metadata hash for a job scheduler.
Returns the number of registered job schedulers.
Returns a range of scheduler keys with their next-run scores, flattened as
[key, score, key, score, …].
Returns the raw processed-children map (child key → serialized value).
Reads the entire queue metadata hash.
Reads a single queue metadata field.
Reads several queue metadata fields at once, in order.
Optionalstart: numberOptionalend: numberOptionalasc: booleanReturns the ttl (ms) of the current rate-limit window.
OptionalmaxJobs: numberReturns whether a queue metadata field exists.
Returns whether a job has finished and (optionally) its result.
OptionalreturnValue: booleanReturns whether a job id is present in the given state.
Returns whether an id corresponds to a registered job scheduler.
Returns whether the queue has reached its concurrency limit.
Moves a (manually rate-limited) job from active back to wait.
Optionaltoken: stringRecovers stalled jobs (active jobs whose lock expired) back to wait.
The ids of the jobs that were moved.
Atomically moves the next eligible job from wait/prioritized to active, returning its data (or the delay/rate-limit signals when none is ready).
Optionalname: stringMoves an active job to the completed state and, optionally, fetches the next job to process.
The next job data tuple when fetchNext is set, plus the
finishedOn timestamp that was recorded.
Moves a job to the delayed state, scheduling it to run after delay ms.
Optionaltoken: stringOptionalopts: MoveToDelayedOptsMoves an active job to the failed state and, optionally, fetches the next job to process.
OptionalfieldsToUpdate: Record<string, any>The next job data tuple when fetchNext is set, plus the
finishedOn timestamp that was recorded.
Moves a parent job to the waiting-children state.
Optionalopts: MoveToWaitingChildrenOptstrue if moved, false if there are pending dependencies.
Irreversibly destroys the queue and all of its contents.
A cursor; 0 when obliteration is complete.
Subscribes to normalized backend lifecycle events ('ready', 'error',
'close'), derived from the underlying connection(s).
Paginates a datastore set or hash, optionally fetching the jobs themselves.
Parses a flow child/dependency node key ("<qualifiedName>:<id>") back
into the components needed to locate the job: its queue keyspace prefix
(empty for backends without a prefix), queueName and id. Inverse of the
backend's key format; used when walking a flow tree.
Pauses or resumes the whole queue.
Promotes a single delayed job so it can be processed as soon as possible.
Promotes up to count delayed jobs back to wait.
Optionalcount: numberA cursor; 0 when there are no more jobs to promote.
Publishes a custom event to the queue's event stream.
The id of the appended event entry.
Blocks (up to blockTimeout ms) reading the queue's event stream for
entries newer than id, returning the raw stream entries (or a falsy value
on timeout). For the Redis adapter this is an XREAD ... BLOCK.
Re-establishes the backend's blocking connection after an interrupt.
Removes a job and (optionally) its children.
1 if removed, 0 if it (or a dependency) was locked.
Removes the child→parent dependency for a not-yet-finished child.
true if the dependency existed and was removed.
Removes a deduplication key if it still maps to the given job.
1 if removed, 0 otherwise.
Removes the deprecated priority helper key.
The number of keys removed.
Removes orphaned job keys that exist in the datastore but are not referenced by any queue state set.
Optionalcount: numberOptionallimit: numberThe total number of orphaned jobs removed.
Removes one or more queue metadata fields.
Removes the rate-limit key.
The number of keys removed.
Removes all unprocessed children of a job.
Reprocesses a finished (failed/completed) job, moving it back to wait.
Optionalopts: RetryOptionsMoves up to count finished jobs of the given state back to wait.
Optionalstate: FinishedStatusOptionalcount: numberOptionaltimestamp: numberA cursor; 0 when there are no more jobs to move.
Retries a failed/active job immediately by pushing it back to wait.
Optionaltoken: stringOptionalopts: RetryJobOptsSets a human-readable name on the underlying connection (for observability). No-op for backends that have no such concept.
Sets one or more queue metadata fields.
Sets the global rate-limit window for the next jobs.
Builds a namespaced sub-key/identifier of the given type for this queue
(e.g. a job's "<qualifiedName>:<id>:dependencies" key).
Trims the event stream to an approximate maximum length.
The number of entries removed.
OptionalproducerId: stringUpdates a job's progress and emits the corresponding event.
Blocks (up to blockTimeout seconds) until the queue signals that a new
job may be available, returning the next "block-until" timestamp.
For the Redis adapter this is a BZPOPMIN on the marker sorted set using
the adapter's own dedicated blocking connection; other adapters may
implement it via LISTEN/NOTIFY, change-data-capture or polling.
The marker member/score on success, or null on timeout.
Resolves once the backend's underlying connection(s) are ready to accept operations.
IQueueBackend
Database-agnostic contract describing every high-level operation that the Queue, Worker and Job classes need in order to function. The goal of this interface is to express the queue semantics ("move job to active", "extend lock", "promote job", …) independently of the underlying datastore.
Built-in implementations currently include the Redis adapter (RedisQueueBackend) and the PostgreSQL adapter. Both fulfil the same operations over different datastores without requiring any change to
Queue,WorkerorJob.The method names and signatures intentionally mirror the existing
RedisQueueBackendclass so that the Redis adapter is a near drop-in implementation. Operations that used to be performed via direct datastore commands scattered across the three classes (queue metadata, job getters, the blocking "wait for next job" primitive, …) have been promoted into this interface so that the three classes never need to talk to the datastore directly.Remarks
Low-level, Redis-specific helpers (Lua KEYS/ARGV builders, error-code mapping,
runCommand, …) are deliberately not part of this contract. They remain private implementation details of the Redis adapter.The interface intentionally exposes no connection or transaction type: a concrete adapter owns its connection(s). For example, the Redis adapter is built from a context that provides an IRedisClient (plus a dedicated blocking client for IQueueBackend.waitForJob), so callers never thread a connection or transaction through an operation.