{"id":43560,"library":"pg-jobs","title":"pg-jobs","description":"A simple yet powerful PostgreSQL-backed job queue for Node.js (version 4.4.2). It provides persistent job creation, scheduled processing, and immediate processing with locking. Unlike alternative libraries (e.g., Kue, Bull) that require Redis, pg-jobs leverages PostgreSQL for storage and atomic operations, making it ideal for projects already using PostgreSQL. The library has a low release cadence but is stable for production use. Key features: job scheduling with delays, concurrent worker support, and automatic table creation via migrations.","status":"active","version":"4.4.2","language":"javascript","source_language":"en","source_url":"git://github.com/noblesamurai/node-pg-jobs","tags":["javascript","job","queue","postgres"],"install":[{"cmd":"npm install pg-jobs","lang":"bash","label":"npm"},{"cmd":"yarn add pg-jobs","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-jobs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"PostgreSQL client for Node.js, required for database operations.","package":"pg","optional":false}],"imports":[{"note":"Default export: the function that initializes the queue with connection options.","wrong":"import { jobQueue } from 'pg-jobs'","symbol":"default","correct":"import jobQueue from 'pg-jobs'"},{"note":"Method on the queue instance. The second argument is processIn delay in milliseconds, not a callback.","wrong":"jobs.create(data, done, delay)","symbol":"create","correct":"import jobQueue from 'pg-jobs'; const jobs = jobQueue({ db: 'postgres://...' }); jobs.create(data, delay, done)"},{"note":"process() requires a done callback for error handling. It iterates jobs synchronously.","wrong":"jobs.process(worker) without done callback","symbol":"process","correct":"import jobQueue from 'pg-jobs'; const jobs = jobQueue({ db: 'postgres://...' }); jobs.process(worker, done)"}],"quickstart":{"code":"import jobQueue from 'pg-jobs';\n\nconst jobs = jobQueue({\n  db: process.env.DATABASE_URL ?? 'postgres://localhost/mydb'\n});\n\n// Create a job that will be processed after 2 seconds\njobs.create({\n  type: 'email',\n  to: 'user@example.com',\n  subject: 'Hello'\n}, 2000, (err) => {\n  if (err) console.error('Failed to create job', err);\n  else console.log('Job created');\n});\n\n// Worker function to process jobs\nfunction worker(id, jobData, done) {\n  console.log('Processing job', id, jobData);\n  // Simulate work\n  done(null, jobData, 1000); // Re-process after 1 second\n}\n\n// Start processing jobs\njobs.process(worker, (err) => {\n  if (err) console.error('Processor error', err);\n});","lang":"typescript","description":"Demonstrates creating a new job with a delay, defining a worker function with done callback, and starting the processing loop."},"warnings":[{"fix":"Update Node.js to >=10 and pg to >=8.","message":"pg-jobs v4 drops support for Node.js < 10 and requires pg v8+. If you use older Node or pg, upgrade.","severity":"breaking","affected_versions":"<4.0.0"},{"fix":"Use 0 for immediate processing or omit/use null only if you don't want retries.","message":"The 'processIn' argument in jobs.create() is in milliseconds. Passing null means the job will never be serviced again, not immediate processing.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use process managers (e.g., cluster) to run multiple worker processes.","message":"jobs.process() runs synchronously; calling it multiple times from the same process will process jobs sequentially, not in parallel. To run workers concurrently, spawn multiple processes.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Replace jobs.stopProcessing() with jobs.stop() in your code.","message":"jobs.stopProcessing() is deprecated in v4.4. Use jobs.stop() instead.","severity":"deprecated","affected_versions":">=4.4.0"}],"env_vars":null,"search_vec":"'4.4.2':16 'alreadi':53 'altern':30 'atom':46 'automat':79 'back':10 'bull':34 'cadenc':62 'concurr':75 'creation':21,81 'delay':74 'e.g':32 'featur':70 'ideal':50 'immedi':25 'javascript':84 'job':3,11,20,40,71,85 'key':69 'kue':33 'leverag':41 'librari':31,57 'lock':28 'low':60 'make':48 'migrat':83 'node.js':14 'oper':47 'persist':19 'pg':2,39 'pg-job':1,38 'postgr':87 'postgresql':9,42,55 'postgresql-back':8 'power':7 'process':23,26 'product':67 'project':52 'provid':18 'queue':12,86 'redi':37 'releas':61 'requir':36 'schedul':22,72 'simpl':5 'stabl':65 'storag':44 'support':77 'tabl':80 'unlik':29 'use':54,68 'version':15 'via':82 'worker':76 'yet':6","created_at":"2026-06-05T17:00:23.163454+00:00","updated_at":"2026-06-05T17:00:23.163454+00:00","problems":[{"fix":"Ensure PostgreSQL is running and DATABASE_URL is correct.","cause":"PostgreSQL server is not running or connection string is wrong.","error":"Error: connect ECONNREFUSED 127.0.0.1:5432"},{"fix":"Call jobQueue(options) first: const jobs = jobQueue(options); then jobs.create(...).","cause":"Trying to use jobs.create on the imported module instead of on an initialized instance.","error":"TypeError: jobs.create is not a function"},{"fix":"Run migrations: db-migrate up -m node_modules/pg-jobs/migrations/ --config database.json","cause":"Migrations have not been run for the required table.","error":"Error: relation \"node_pg_jobs_dev\" does not exist"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/noblesamurai/node-pg-jobs#readme","github":"git://github.com/noblesamurai/node-pg-jobs","docs":null,"changelog":null,"pypi":null,"npm":"pg-jobs","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}