BaseJobQueue class

Shared base of the three concrete queues, implementing everything that does not depend on which end of the queue you are.

Signature:

export declare abstract class BaseJobQueue<T, U> implements AnyJobQueue<T> 

Implements: AnyJobQueue<T>

Remarks

Not usable on its own and not meant to be subclassed outside this package: it leaves BaseJobQueue.imq to be assigned by a subclass constructor, so a subclass that forgets to do so fails on first use. Reach for JobQueue, JobQueueWorker or JobQueuePublisher instead.

T is the concrete queue type, so inherited methods resolve to it rather than to this base; U is the job body type.

Constructors

Constructor

Modifiers

Description

(constructor)(options)

protected

Stores the options and resolves the logger, leaving the broker connection to the subclass.

Properties

Property

Modifiers

Type

Description

drainRequeues

protected

readonly

boolean

Whether abandoned jobs are pushed back on the way out.

drains

protected

readonly

boolean

Whether this queue drains before shutting down. Resolved once, at construction, from JobQueueOptions.drain falling back to IMQ_DRAIN_ENABLE.

drainTimeout

protected

readonly

number

Milliseconds a drain waits before abandoning what is left.

handler?

protected

JobQueuePopHandler<U>

(Optional) The handler registered by onPop, if any.

imq

protected

IMessageQueue

The underlying @imqueue/core message queue this job queue runs on.

inFlight?

protected

readonly

Set<InFlight>

(Optional) Work this queue is waiting on, allocated only while BaseJobQueue.drains is on — with draining off there is nothing to track and nothing to allocate.

logger

readonly

ILogger

Logger this queue reports through — JobQueueOptions.logger when one was given, console otherwise.

name

readonly

string

Name of this queue, as given in JobQueueOptions.name.

options

protected

JobQueueOptions

The options this queue was constructed with, kept so that accessors like BaseJobQueue.name can read them back. Treat as read-only — nothing re-reads them after the broker connection is made, so changing one here has no effect on a running queue.

Methods

Method

Modifiers

Description

destroy()

Destroys the job queue, closing the broker connection and releasing its resources. Not reversible — construct a new queue to carry on.

drainDestroy()

Drain step four: release the transport. Last, because it closes the connection every step above needed.

drainRequeue()

Drain step three: put back whatever the budget ran out on.

drainStop(signal)

Drain step one: stop consuming. The reader goes, the writer stays — which is what lets the rest of the drain publish anything at all.

drainWait()

Drain step two: wait for work already in flight, bounded by JobQueueOptions.drainTimeout.

handleMessage(message, id)

protected

Handles one popped message: runs the handler, then acts on what it asked for.

start()

Starts processing the job queue.

stop()

Stops processing the job queue, leaving it able to start again.

track(work, message)

protected

Records a unit of work as in flight until it settles.

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.