@cran/pg.q
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

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)
);

Readme

Keywords

Package Sidebar

Install

npm i @cran/pg.q

Weekly Downloads

2

Version

0.1.8

License

CC-BY-ND-4.0

Unpacked Size

17.7 kB

Total Files

15

Last publish

Collaborators

  • common-cranberry