HyperdriveJobQueue
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:125
A job queue in a SQL table on D1 or another SQLite, Postgres (Hyperdrive) or MySQL.
With leaseMs, a processing job’s process_at holds its lease’s end, so
the table needs no new column. dequeue() settles expired leases and takes
the next job with statements that each settle or take a job only once:
Postgres skips rows another dequeue() has locked, SQLite runs each
statement under its write lock, and MySQL locks the rows it changes, which
holds only when the client provides transaction(). Without
onLeaseExpired, Postgres does both in one statement; with it, the
callbacks run between the two, so they do not shorten the new lease.
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
섹션 제목: “Type Parameters”T
Implements
섹션 제목: “Implements”JobQueue<T>
Constructors
섹션 제목: “Constructors”Constructor
섹션 제목: “Constructor”new HyperdriveJobQueue<
T>(client,options?):HyperdriveJobQueue<T>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:133
Parameters
섹션 제목: “Parameters”client
섹션 제목: “client”options?
섹션 제목: “options?”HyperdriveJobQueueOptions<T> = {}
Returns
섹션 제목: “Returns”HyperdriveJobQueue<T>
Methods
섹션 제목: “Methods”checkpoint()
섹션 제목: “checkpoint()”checkpoint(
jobId,data,attempt):Promise<void>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:256
Saves a message job’s progress under the attempt fence and, with
leaseMs, renews the lease. Needs a cache-disabled Hyperdrive: when the
driver reports no affected-row count, ownership is verified with a plain
read, which a query cache could answer with a stale row.
Parameters
섹션 제목: “Parameters”jobId
섹션 제목: “jobId”string
data
섹션 제목: “data”T
attempt
섹션 제목: “attempt”number
Returns
섹션 제목: “Returns”Promise<void>
Implementation of
섹션 제목: “Implementation of”cleanupTerminal()
섹션 제목: “cleanupTerminal()”cleanupTerminal(
options?):Promise<number>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:477
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
섹션 제목: “Parameters”options?
섹션 제목: “options?”JobQueueCleanupOptions | JobStatus[]
Returns
섹션 제목: “Returns”Promise<number>
Implementation of
섹션 제목: “Implementation of”clear()
섹션 제목: “clear()”clear():
Promise<void>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:467
Returns
섹션 제목: “Returns”Promise<void>
Implementation of
섹션 제목: “Implementation of”close()
섹션 제목: “close()”close():
Promise<void>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:518
Returns
섹션 제목: “Returns”Promise<void>
complete()
섹션 제목: “complete()”complete(
jobId,_result?,options?):Promise<void>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:283
Parameters
섹션 제목: “Parameters”jobId
섹션 제목: “jobId”string
_result?
섹션 제목: “_result?”any
options?
섹션 제목: “options?”JobSettleOptions = {}
Returns
섹션 제목: “Returns”Promise<void>
Implementation of
섹션 제목: “Implementation of”dequeue()
섹션 제목: “dequeue()”dequeue(
options?):Promise<Job<T> |undefined>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:230
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.
Jobs in options.running are left as they are.
Parameters
섹션 제목: “Parameters”options?
섹션 제목: “options?”JobDequeueOptions = {}
Returns
섹션 제목: “Returns”Promise<Job<T> | undefined>
Implementation of
섹션 제목: “Implementation of”enqueue()
섹션 제목: “enqueue()”enqueue(
type,data,options?):Promise<Job<T>>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:164
Parameters
섹션 제목: “Parameters”type
섹션 제목: “type”string
data
섹션 제목: “data”T
options?
섹션 제목: “options?”{ delay?: number; maxAttempts?: number; metadata?: Record<string, any>; priority?: number; } | undefined
Returns
섹션 제목: “Returns”Promise<Job<T>>
Implementation of
섹션 제목: “Implementation of”fail()
섹션 제목: “fail()”fail(
jobId,error,retry?,options?):Promise<void>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:317
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,
unless options.attempt fences the call to the attempt that owns it.
Parameters
섹션 제목: “Parameters”jobId
섹션 제목: “jobId”string
error
섹션 제목: “error”string | Error
retry?
섹션 제목: “retry?”JobRetryDirective = ...
options?
섹션 제목: “options?”JobSettleOptions = {}
Returns
섹션 제목: “Returns”Promise<void>
Implementation of
섹션 제목: “Implementation of”getJob()
섹션 제목: “getJob()”getJob(
jobId):Promise<Job<T> |undefined>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:437
Parameters
섹션 제목: “Parameters”jobId
섹션 제목: “jobId”string
Returns
섹션 제목: “Returns”Promise<Job<T> | undefined>
Implementation of
섹션 제목: “Implementation of”init()
섹션 제목: “init()”init():
Promise<void>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:146
Returns
섹션 제목: “Returns”Promise<void>
nextDueAt()
섹션 제목: “nextDueAt()”nextDueAt():
Promise<Date|undefined>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:423
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
섹션 제목: “Returns”Promise<Date | undefined>
Implementation of
섹션 제목: “Implementation of”peek()
섹션 제목: “peek()”peek():
Promise<Job<T> |undefined>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:382
The job dequeue() would take next, including one whose lease expired,
shown as it will be once it is due again. Changes nothing.
Returns
섹션 제목: “Returns”Promise<Job<T> | undefined>
Implementation of
섹션 제목: “Implementation of”remove()
섹션 제목: “remove()”remove(
jobId):Promise<boolean>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:451
Parameters
섹션 제목: “Parameters”jobId
섹션 제목: “jobId”string
Returns
섹션 제목: “Returns”Promise<boolean>
Implementation of
섹션 제목: “Implementation of”size()
섹션 제목: “size()”size():
Promise<number>
Defined in: packages/messaging/src/adapters/cloudflare/hyperdrive-job-queue.ts:402
How many jobs are due now, including those whose lease expired.
Returns
섹션 제목: “Returns”Promise<number>