Skip to content
PACKAGES

workQueue()

Build a graph-visible work queue over a MessageBus subscription.

import { workQueue } from "@graphrefly/ts/work-queue";
function workQueue(
graph: Graph,
opts: WorkQueueOptions<T>,
): WorkQueue<T>
ParameterTypeDescription
graphGraphGraph that owns the queue nodes and command projections.
optsWorkQueueOptions<T>Queue identity, source topic/subscription, bus, retry, lease, and clock options.

A WorkQueue handle with graph nodes plus command helpers for submit, claim, complete, fail, cancel, schedule, and projections.

import { graph } from "@graphrefly/ts/graph";
import { messageBus } from "@graphrefly/ts/messaging";
import { workQueue } from "@graphrefly/ts/work-queue";
const g = graph();
const bus = messageBus(g, { topics: ["jobs.submit"], name: "jobs" });
const queue = workQueue(g, {
queueId: "jobs",
topic: "jobs.submit",
subscriptionId: "workers",
bus,
});
queue.submit({ task: "index" });

packages/ts/src/work-queue/index.ts