Anyone used pg-boss? (Postgres as a message queue for background jobs?)
github.com·18h·
Discuss: r/node
📮Message Queues
Preview
Report Post

Queueing jobs in Postgres from Node.js like a boss.

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 Postgres’s …

Similar Posts

Loading similar posts...