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...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help