From ac948857474d6094071efd6828e2fb117400c957 Mon Sep 17 00:00:00 2001 From: Tim Jones Date: Tue, 27 Aug 2024 07:38:37 -0500 Subject: [PATCH] fix scheduling debounce (#479) --- .npmignore | 3 ++- {test => examples}/readme.js | 6 +----- examples/schedule.js | 26 ++++++++++++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- src/timekeeper.js | 2 +- 6 files changed, 33 insertions(+), 10 deletions(-) rename {test => examples}/readme.js (82%) create mode 100644 examples/schedule.js diff --git a/.npmignore b/.npmignore index 9e4d4d91..7adf2a9b 100644 --- a/.npmignore +++ b/.npmignore @@ -5,4 +5,5 @@ docs test .editorconfig *.tgz -coverage \ No newline at end of file +coverage +examples \ No newline at end of file diff --git a/test/readme.js b/examples/readme.js similarity index 82% rename from test/readme.js rename to examples/readme.js index 1b200bd4..4403a0a1 100644 --- a/test/readme.js +++ b/examples/readme.js @@ -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') @@ -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() diff --git a/examples/schedule.js b/examples/schedule.js new file mode 100644 index 00000000..d7967a05 --- /dev/null +++ b/examples/schedule.js @@ -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) + }) diff --git a/package-lock.json b/package-lock.json index 3fb24db3..03cc2846 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pg-boss", - "version": "10.0.4", + "version": "10.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pg-boss", - "version": "10.0.4", + "version": "10.0.5", "license": "MIT", "dependencies": { "cron-parser": "^4.0.0", diff --git a/package.json b/package.json index 44f31c69..8c7a0fc3 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/timekeeper.js b/src/timekeeper.js index 2c69497b..20a4462d 100644 --- a/src/timekeeper.js +++ b/src/timekeeper.js @@ -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)