Skip to content

Commit

Permalink
fix scheduling debounce (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit authored Aug 27, 2024
1 parent 80bcb42 commit ac94885
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ docs
test
.editorconfig
*.tgz
coverage
coverage
examples
6 changes: 1 addition & 5 deletions test/readme.js → examples/readme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const helper = require('./testHelper')
const { delay } = require('../src/tools')
const helper = require('../test/testHelper')

async function readme () {
const PgBoss = require('../src')
Expand All @@ -20,9 +19,6 @@ async function readme () {
await boss.work(queue, async ([job]) => {
console.log(`received job ${job.id} with data ${JSON.stringify(job.data)}`)
})

await delay(2000)
await boss.stop()
}

readme()
Expand Down
26 changes: 26 additions & 0 deletions examples/schedule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const helper = require('../test/testHelper')

async function schedule () {
const PgBoss = require('../src')
const boss = new PgBoss(helper.getConnectionString())

boss.on('error', console.error)

await boss.start()

const queue = 'scheduled-queue'

await boss.createQueue(queue)

await boss.schedule(queue, '*/2 * * * *', { arg1: 'schedule me' })

await boss.work(queue, async ([job]) => {
console.log(`received job ${job.id} with data ${JSON.stringify(job.data)} on ${new Date().toISOString()}`)
})
}

schedule()
.catch(err => {
console.log(err)
process.exit(1)
})
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-boss",
"version": "10.0.4",
"version": "10.0.5",
"description": "Queueing jobs in Postgres from Node.js like a boss",
"main": "./src/index.js",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/timekeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Timekeeper extends EventEmitter {
const scheduled = schedules
.filter(i => this.shouldSendIt(i.cron, i.timezone))
.map(({ name, data, options }) =>
({ name: QUEUES.SEND_IT, data: { name, data, options }, options: { singletonKey: name, singletonSeconds: 60 } }))
({ name: QUEUES.SEND_IT, data: { name, data, options }, singletonKey: name, singletonSeconds: 60 }))

if (scheduled.length > 0 && !this.stopped) {
await this.manager.insert(scheduled)
Expand Down

0 comments on commit ac94885

Please sign in to comment.