OptionallistenClientName: string
When set, the name applied to this backend's dedicated connection (its
application_name) so getWorkers can discover it — the PostgreSQL
analogue of the Redis worker's named blocking connection. Only workers
pass it; QueueEvents name themselves via setName.
Truthy 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.
Backends that don't address jobs by key return an empty map; PostgreSQL
addresses rows by (queue, id) columns instead.
PostgreSQL LISTEN/NOTIFY has no minimum block granularity, so any
positive timeout is fine; we mirror the Redis backend's smallest unit.
The queue's qualified name. With a schema-based namespace there is no prefix, so the qualified name is simply the queue name.
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.
Adds 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.
Removes jobs in a given state that are older than timestamp.
The ids of the removed jobs.
Clears a job's logs, optionally keeping the most recent keepLogs rows.
OptionalkeepLogs: numberReturns a backend identifier used by the generic API; PostgreSQL discovery
relies on setName setting application_name on the dedicated
LISTEN client.
Closes the backend and its underlying connection(s), waiting for any in-flight work to settle.
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.
Removes 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.
Optional_prefix: 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.
Returns 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.
Recovers 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.
Optional_opts: 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.
Paginates a datastore set or hash, optionally fetching the jobs themselves.
Parses a PostgreSQL flow child key ("<queue>:<id>") into its components.
There is no keyspace prefix, so prefix is always empty. Inverse of
toKey.
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 hashes (job data present but not referenced by any state set). This is a Redis keyspace-maintenance concern: on PostgreSQL a job is a single relational row inserted transactionally with its state, so orphans cannot exist and there is nothing to remove. Always returns 0.
Optional_count: numberOptional_limit: numberRemoves 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.
Moves 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 identifier of the given type ("<queue>:<type>"),
used e.g. for flow dependency identifiers. No prefix is involved.
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 a job for this queue may be
available, via LISTEN/NOTIFY. Producers notify the shared bullmq_jobs
channel with the queue name as payload (in add_job), so a producer
in any process wakes a blocked worker immediately. Returns a marker
(score 0 = "check now") or null on timeout. The Redis backend
implements this with BZPOPMIN.
Resolves once the backend's underlying connection(s) are ready to accept operations.
PostgreSQL implementation of IQueueBackend.
Fulfils the same database-agnostic contract as RedisQueueBackend, but backed by a PostgreSQL database: queue operations are expressed as SQL / PL/pgSQL functions (created by the migrations), job state lives in a single
jobtable keyed by(queue, id)with astatecolumn and partial indexes, claiming usesFOR UPDATE SKIP LOCKED, and the blocking "wait for job" primitive usesLISTEN/NOTIFY.The class owns its PostgresConnection; the high-level classes (Queue, Worker, FlowProducer) depend only on IQueueBackend and never touch a
pgclient directly.