Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timgit/pg-boss
Queueing jobs in Postgres from Node.js like a boss
https://github.com/timgit/pg-boss
job node nodejs postgres postgresql queue
Last synced: 7 days ago
JSON representation
Queueing jobs in Postgres from Node.js like a boss
- Host: GitHub
- URL: https://github.com/timgit/pg-boss
- Owner: timgit
- License: mit
- Created: 2016-02-27T22:55:12.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-12T22:40:50.000Z (24 days ago)
- Last Synced: 2024-10-23T06:57:28.940Z (13 days ago)
- Topics: job, node, nodejs, postgres, postgresql, queue
- Language: JavaScript
- Homepage:
- Size: 1.88 MB
- Stars: 2,105
- Watchers: 22
- Forks: 158
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- postgresql-is-awesome - pg-boss - Queueing jobs in Node.js using PostgreSQL like a boss
README
Queueing jobs in Postgres from Node.js like a boss.
[![npm version](https://badge.fury.io/js/pg-boss.svg)](https://badge.fury.io/js/pg-boss)
[![Build](https://github.com/timgit/pg-boss/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/timgit/pg-boss/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/timgit/pg-boss/badge.svg?branch=master)](https://coveralls.io/github/timgit/pg-boss?branch=master)```js
async function readme() {
const PgBoss = require('pg-boss');
const boss = new PgBoss('postgres://user:pass@host/database');boss.on('error', console.error)
await boss.start()
const queue = 'readme-queue'
await boss.createQueue(queue)
const id = await boss.send(queue, { arg1: 'read me' })
console.log(`created job ${id} in queue ${queue}`)
await boss.work(queue, async ([ job ]) => {
console.log(`received job ${job.id} with data ${JSON.stringify(job.data)}`)
})
}readme()
.catch(err => {
console.log(err)
process.exit(1)
})
```pg-boss is a job queue built in Node.js on top of PostgreSQL in order to provide background processing and reliable asynchronous execution to Node.js applications.
pg-boss relies on [SKIP LOCKED](https://www.2ndquadrant.com/en/blog/what-is-select-skip-locked-for-in-postgresql-9-5/), a feature built specifically for message queues to resolve record locking challenges inherent with relational databases. This provides exactly-once delivery and the safety of guaranteed atomic commits to asynchronous job processing.
This will likely cater the most to teams already familiar with the simplicity of relational database semantics and operations (SQL, querying, and backups). It will be especially useful to those already relying on PostgreSQL that want to limit how many systems are required to monitor and support in their architecture.
## Summary
* Exactly-once job delivery
* Create jobs within your existing database transaction
* Backpressure-compatible polling workers
* Cron scheduling
* Queue storage policies to support a variety of rate limiting, debouncing, and concurrency use cases
* Priority queues, dead letter queues, job deferral, automatic retries with exponential backoff
* Pub/sub API for fan-out queue relationships
* Raw SQL support for non-Node.js runtimes via INSERT or COPY
* Serverless function compatible
* Multi-master compatible (for example, in a Kubernetes ReplicaSet)## Requirements
* Node 20 or higher
* PostgreSQL 13 or higher## Installation
```bash
# npm
npm install pg-boss# yarn
yarn add pg-boss
```## Documentation
* [Docs](https://timgit.github.io/pg-boss/)## Contributing
To setup a development environment for this library:```bash
git clone https://github.com/timgit/pg-boss.git
npm install
```To run the test suite, linter and code coverage:
```bash
npm run cover
```The test suite will try and create a new database named pgboss. The [config.json](test/config.json) file has the default credentials to connect to postgres.