Postgres Queue
npm install @cran/pg.q
Distributed Queue Functionality for Postgres
Usage
import { PgQ } from "@cran/pg.q";
import { Pool } from "pg";
const q = new PgQ({
pool: new Pool(/* ... */),
async handler ( payload ) {
// handle payload
},
// optional
target: "default", // ignored if uq is false
fields: {
// unique identifier (should be primary key)
id: "id",
// unique qualifier (can be false to ignore)
uq: "uq",
// retry count field
rc: "rc",
// payload
pl: "pl",
},
});
;(async function main ( ) {
process.on("SIGINT", function onSigint ( ) {
console.log("graceful shutdown...");
q.stop().then(function afterStop ( ) {
process.exit(0);
});
});
await q.start();
})().then(
console.log.bind(console),
console.error.bind(console)
);