SQLiteJobQueue
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:51
A job queue in a SQLite database.
With leaseMs, a processing job’s process_at holds its lease’s end, so
the table needs no new column. A job already processing without a lease,
taken by an earlier version or by a queue without leaseMs, cannot be
told from one whose lease has expired, so it is due at once.
Type Parameters
Section titled “Type Parameters”T
Implements
Section titled “Implements”JobQueue<T>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SQLiteJobQueue<
T>(options?):SQLiteJobQueue<T>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:56
Parameters
Section titled “Parameters”options?
Section titled “options?”SQLiteJobQueueOptions<T> = {}
Returns
Section titled “Returns”SQLiteJobQueue<T>
Methods
Section titled “Methods”cleanupTerminal()
Section titled “cleanupTerminal()”cleanupTerminal(
options?):Promise<number>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:435
Removes finished jobs: completed and failed ones by default, or those
with the given statuses, and with olderThan, only those that finished
before it.
Parameters
Section titled “Parameters”options?
Section titled “options?”JobQueueCleanupOptions | JobStatus[]
Returns
Section titled “Returns”Promise<number>
Implementation of
Section titled “Implementation of”clear()
Section titled “clear()”clear():
Promise<void>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:426
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”close()
Section titled “close()”close():
void
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:466
Returns
Section titled “Returns”void
complete()
Section titled “complete()”complete(
jobId,_result?):Promise<void>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:277
Parameters
Section titled “Parameters”string
_result?
Section titled “_result?”any
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”dequeue()
Section titled “dequeue()”dequeue(
options?):Promise<Job<T> |undefined>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:212
Takes the next due job and, with leaseMs, leases it. Jobs whose lease
expired are due again first, or fail when they have no attempts left.
Parameters
Section titled “Parameters”options?
Section titled “options?”JobDequeueOptions = {}
Returns
Section titled “Returns”Promise<Job<T> | undefined>
Implementation of
Section titled “Implementation of”enqueue()
Section titled “enqueue()”enqueue(
type,data,options?):Promise<Job<T>>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:155
Parameters
Section titled “Parameters”string
T
options?
Section titled “options?”delay?
Section titled “delay?”number
maxAttempts?
Section titled “maxAttempts?”number
metadata?
Section titled “metadata?”Record<string, any>
priority?
Section titled “priority?”number
Returns
Section titled “Returns”Promise<Job<T>>
Implementation of
Section titled “Implementation of”fail()
Section titled “fail()”fail(
jobId,error,retry?):Promise<void>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:294
Counts a failed attempt: the job is due again after retry.delayMs when
retries are enabled and attempts are left, and fails otherwise. A
completed job stays completed, even for a worker whose lease expired.
Parameters
Section titled “Parameters”string
string | Error
retry?
Section titled “retry?”JobRetryDirective = ...
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”getJob()
Section titled “getJob()”getJob(
jobId):Promise<Job<T> |undefined>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:396
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<Job<T> | undefined>
Implementation of
Section titled “Implementation of”nextDueAt()
Section titled “nextDueAt()”nextDueAt():
Promise<Date|undefined>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:380
When dequeue() next has work: the earliest due time of a pending job
or, with leaseMs, lease expiry of a processing one. A time in the past
means dequeue() has work now, even when it only settles an expired
lease, so call dequeue() rather than checking size(). undefined
when no job is pending or leased.
Returns
Section titled “Returns”Promise<Date | undefined>
Implementation of
Section titled “Implementation of”peek()
Section titled “peek()”peek():
Promise<Job<T> |undefined>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:341
The job dequeue() would take next, including one whose lease expired,
shown as it will be once it is due again. Changes nothing.
Returns
Section titled “Returns”Promise<Job<T> | undefined>
Implementation of
Section titled “Implementation of”remove()
Section titled “remove()”remove(
jobId):Promise<boolean>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:412
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”size()
Section titled “size()”size():
Promise<number>
Defined in: packages/messaging/src/queue/sqlite-job-queue.ts:362
How many jobs are due now, including those whose lease expired.
Returns
Section titled “Returns”Promise<number>