In-Process State Adapter

Keep chains and jobs in memory, for tests and single-process scripts that don't need persistence.

The in-process state adapter, createInProcessStateAdapter, is built in: no extra package, imported from queuert. It is meant for tests and single-process scripts. All state is held in memory and lost on process exit. It is synchronous by default, and mode: "async" makes its methods return promises; createInProcessNotifyAdapter, with the same mode option, wakes worker runners in the same process.

No persistence, one process

Nothing is persisted, and state is visible only inside the process that created the adapter, so workers in other processes can't share it. When jobs must survive a restart, use PostgreSQL or SQLite; to run workers across processes, use a shared database such as PostgreSQL, MySQL / MariaDB or Redis, or, on one host, SQLite with the IPC notify adapter.

Setup

src/index.ts

import {
  createClient,
  createInProcessNotifyAdapter,
  createInProcessStateAdapter,
} from "queuert";

const stateAdapter = createInProcessStateAdapter();
const notifyAdapter = createInProcessNotifyAdapter();

const client = createClient({ stateAdapter, notifyAdapter, jobTypes });

Configuration

createInProcessStateAdapter

  • mode "sync"
    "sync" or "async": whether the adapter's methods return their results directly or return promises.
  • The most blocker chains a single job may declare. Declaring more throws BlockerLimitExceededError; see Job Blockers.
  • countCap 10_000
    The per-status count at which countChainsByTypeName and countJobsByTypeName (and the dashboard's type counts) stop counting and report hasMore. A higher cap means a longer index scan per count.
  • generateJobId crypto.randomUUID
    Called for every job created without a caller-supplied id.
  • validateJobId accept all
    Runs on every caller-supplied and generated ID before writing, throwing InvalidJobIdError on failure.
  • generateWorkerId crypto.randomUUID
    Called once for each worker runner created without a workerId; must return a new id on every call.
  • validateWorkerId accept all
    Runs on the configured or generated worker id; createWorkerRunner throws InvalidWorkerIdError on failure.

maxBlockersPerJob and countCap must be positive integers; anything else throws when the adapter is created. The resolved values are readable on stateAdapter.config.

How it works

Serializable transactions (the same isolation model as SQLite; in the "async" mode through an internal lock), with per-type ordered sets and per-chain maps so acquisition and chain lookups work against type- and chain-scoped collections rather than scanning all jobs.

esc

Search guides, integrations and every exported symbol.

↑ ↓ to navigate↵ to open