@zmdb/jobs-postgres
v1.0.0-beta.2
Published
node-postgres JobStore adapter for caller-owned PostgreSQL pools and clients.
Maintainers
Readme
@zmdb/jobs-postgres
@zmdb/jobs-postgres adapts a caller-owned node-postgres Pool, PoolClient, or Client to the JobStore port from @zmdb/jobs.
The caller retains ownership of the supplied PostgreSQL pool or client. Apply jobsPostgresMigrations explicitly before use. store.close({ graceMs }) stops admission and drains or cancels
operations under a bounded deadline; only internally acquired pool connections are released.
Install
yarn add @zmdb/[email protected] @zmdb/[email protected] pg@^8.23.0Prerelease (
1.0.0-beta.2). Requires Node.js 26+ and is ESM-only. Ships built ESM.js+.d.tsunder./dist.
The required peers are @zmdb/[email protected] and pg@^8.23.0. Neither jobs, pg nor this adapter is installed by yarn add @zmdb/[email protected]. Portable jobs owns queues, workers, retries and
scheduling; the provider owns its fresh schema.
Usage
import { Pool } from 'pg';
import { createPgJobStore } from '@zmdb/jobs-postgres';
const connectionString = process.env.DATABASE_URL;
if (connectionString === undefined) throw new Error('DATABASE_URL is required');
const pool = new Pool({ connectionString });
const store = createPgJobStore(pool, {
prepared: true,
maxCacheSize: 128,
});
// Pass store to createQueue/createWorker. The application still owns pool.
void store;prepared and maxCacheSize preserve the bounded prepared-statement behavior of the zmdb PostgreSQL driver. cancelVia may name a caller-owned client that can cancel work through a second
connection. For the borrowed pool or client, the adapter never calls end() or release(); the caller performs that shutdown after workers have drained. Internally acquired pool clients are released
after their operations finish or are cancelled.
Entry points
@zmdb/jobs-postgres—createPgJobStore,pgJobEnqueuer,jobsPostgresMigrations,PgJobClient,PgJobTransactionClient,PgJobStore, andPgJobStoreOptions.
Documentation
Full docs: https://ambasta.github.io/zmdb/
License
GNU General Public License v3.0 or later (GPL-3.0-or-later) — see LICENSE.
