@frank/jobs (0.1.5)
Installation
@frank:registry=npm install @frank/jobs@0.1.5"@frank/jobs": "0.1.5"About this package
@frank/jobs
Durable Postgres job queue for Frank products: enqueue, a leased worker loop,
SQL for job_queue (runner lanes, dedupe, product-owned priority), and a
transactional outbox. Ported unchanged in behaviour from Blockwise
worker/index.ts, src/lib/providers/job-queue-enqueue.ts,
worker/crm-provision-host.ts and the four job_queue migrations.
Public API
enqueueQueuedJob(service, input)/cancelQueuedJob(service, input)createWorker(service, config)->{ runOnce, reap, start, shutdown }hostLaneConfig({ kind, handler })-> single-kind host-lane configresolveWorkerConfig(config),configFromEnv(),BLOCKWISE_JOB_KIND_PRIORITYpriorityFunctionSql(tiers)/priorityCaseSql(tiers)/rankForKind(tiers, k)kindPriorityTiers(priority)-> validated tiers (normalises a flat list)createCompensationFetch(transport, fetchImpl)LeaseLostError,WorkerRestartRequiredError, and the types
Config
The caller builds { kindPriority, handlers }. kindPriority is rank tiers,
highest first: readonly (readonly string[])[]; kinds in one tier share its
rank. The tier "*" (alone in it) ranks unlisted kinds; without it they rank
after the last tier. A legacy flat string list also works: each kind becomes
its own tier. Validation throws on duplicate kinds, a duplicate or mixed
"*", and empty tiers. The claim SQL honours it via queue_job_priority;
install it with priorityFunctionSql() and rebuild
job_queue_priority_claim_idx. configFromEnv() reads the Blockwise
WORKER_* names. sql/001_job_queue.sql and sql/002_job_queue_rpcs.sql
build the queue; sql/003_outbox.sql is the generic transactional outbox.
Example
const worker = createWorker(service, {
kindPriority: [["publish.meta.execute", "publish.meta.mutate"],
["*"], ["reporting.refresh"]],
handlers: { "publish.meta.execute": myHandler },
});
await worker.start();
Dependencies
Development dependencies
| ID | Version |
|---|---|
| @types/node | ^22.20.4 |