diff --git a/.npmignore b/.npmignore index 9e4d4d9..7adf2a9 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 1b200bd..4403a0a 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 0000000..d7967a0 --- /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 3fb24db..03cc284 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 44f31c6..8c7a0fc 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 2c69497..20a4462 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)