Registry / database / pg-job-queue

pg-job-queue

JSON →
library0.3.3jsnpmunverified

A job queue for Node.js based on PostgreSQL, allowing you to define job handlers and process jobs using a CLI tool. The package is at version 0.3.3, with infrequent releases. It supports custom log, error, and shutdown handlers but has limited documentation. It differs from alternatives like Bull or Bee by using PostgreSQL as the backing store, which may be beneficial for teams already using PostgreSQL.

npm install pg-job-queue
INSTALL
IMPORT
SIG · PG-JOB-QUEUE
P
pg-job-queue
databasejavascriptv0.3.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const jobqueue = require('pg-job-queue')
import jobqueue from 'pg-job-queue'
CJS only; no ESM support. Use require.
JobQueue
const { JobQueue } = require('pg-job-queue')
const JobQueue = require('pg-job-queue').default
Named export available; avoid .default which is undefined.
process-job-queue CLI
node_modules/.bin/process-job-queue -f ./handlers.js -c postgres://...
npx process-job-queue
CLI is not published to npm as a bin, only inside package. Must reference via full path or node_modules/.bin

Creates a job queue instance, adds a job, defines a handler module, and runs the CLI processing loop.

const jobqueue = require('pg-job-queue'); const queue = new jobqueue('postgres://postgres@localhost/my-job-queue'); queue.addJob({ type: 'sendmail.welcome', data: { toAddress: 'demo@example.com', message: 'hello' } }); // handlers.js module.exports = { sendmail: { welcome: function(job) { return Promise.resolve().then(() => job.finish()); } } }; // Run with: node_modules/pg-job-queue/bin/process-job-queue -f ./handlers.js -c postgres://postgres@localhost/my-job-queue
Debug
Known issues
gotchaHandler must be nested to match job type with dots (e.g., 'sendmail.welcome' maps to exports.sendmail.welcome).
fix
Ensure job type uses dots to match nested handler path.
affects: >=0.0.0
gotchaCLI does not have a bin entry; must be run from node_modules/.bin directory.
fix
Use node_modules/pg-job-queue/bin/process-job-queue or add a script in package.json.
affects: >=0.0.0
gotchaNo ESM support; using import will throw error.
fix
Use require() instead of import.
affects: >=0.0.0
gotchaThe job.finish() must be called explicitly; otherwise job remains pending.
fix
Ensure every handler calls job.finish() (or returns promise that resolves after finish).
affects: >=0.0.0
gotchaPostgreSQL connection string must be valid; no default provided.
fix
Provide a valid connection string like postgres://user:password@host/db
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pg-job-queue'
Package not installed or missing from node_modules.
fix
Run npm install pg-job-queue
TypeError: jobqueue is not a constructor
Using ES6 import instead of require or named import incorrectly.
fix
Use const jobqueue = require('pg-job-queue');
Error: No handler defined for job type <type>
Handler module does not export a function matching the job type hierarchy.
fix
Export a nested object matching the dotted job type; e.g., exports.sendmail.welcome
Upgrade
Version history
0.3.3latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client required for database operations
Agent activity
9 hits · last 30 days
node
8
Resources
pg-job-queue — npm install pg-job-queue · libregistry