Skip to main content
Module

x/kvmq/mod.ts>Queue

Library inspired by BullMQ for Deno
Latest
class Queue
import { Queue } from "https://deno.land/x/kvmq@v0.3.0/mod.ts";

Represents a job queue in the database.

Allows listing jobs in the queue and pushing new jobs.

Constructors

new
Queue(db: Deno.Kv, key: Deno.KvKeyPart)

Initialize a job queue.

Type Parameters

State

Type of custom state data that is passed to the worker when processing a job.

Properties

readonly
db: Deno.Kv

Kv database to use for storing the queue.

readonly
key: Deno.KvKeyPart

Key prefix to use for storing queue's data.

Methods

Shorthand for constructing a Worker for this queue.

deleteJob(id: JobId): Promise<void>

Removes a job from the queue.

TODO: throw if locked.

deleteWaitingJobs(): Promise<void>

Removes all jobs that aren't currently being processed from the queue.

TODO: make this atomic.

getAllJobs(): Promise<Array<JobEntry<State>>>

Returns an array of all jobs in this queue, from front to back.

The jobs are sorted by priority first, then by creation date, ascending.

listenUpdates(onUpdate: (jobs: Array<JobEntry<State>>) => void, options: { signal?: AbortSignal; pollIntervalMs?: number; }): Promise<void>

Listens for queue updates.

Note: currently it just polls the queue every few seconds.

pause(): Promise<void>

Pauses the processing of this queue.

Sets a paused flag in the database that is checked by workers.

A paused queue will not process new jobs until resumed, but current jobs being processed will continue until they are finalized.

pushJob(state: State, options?: JobOptions): Promise<Job<State>>

Creates a new job and adds it to the queue.

Returns job ID.

resume(): Promise<void>

Resumes the processing of this queue.

Resets a paused flag in the database that is checked by workers.