diff --git a/package-lock.json b/package-lock.json index 8676e1d..62fe247 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pg-boss", - "version": "10.0.6", + "version": "10.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pg-boss", - "version": "10.0.6", + "version": "10.1.0", "license": "MIT", "dependencies": { "cron-parser": "^4.0.0", diff --git a/package.json b/package.json index 7842c7a..a55974d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pg-boss", - "version": "10.0.6", + "version": "10.1.0", "description": "Queueing jobs in Postgres from Node.js like a boss", "main": "./src/index.js", "engines": { diff --git a/src/manager.js b/src/manager.js index caf7262..bea0e41 100644 --- a/src/manager.js +++ b/src/manager.js @@ -408,7 +408,9 @@ class Manager extends EventEmitter { this.config.retryBackoff // 6 ] - return await db.executeSql(this.insertJobsCommand, params) + const { rows } = await db.executeSql(this.insertJobsCommand, params) + + return (rows.length) ? rows.map(i => i.id) : null } getDebounceStartAfter (singletonSeconds, clockOffset) { diff --git a/src/plans.js b/src/plans.js index a172c4e..ba72e03 100644 --- a/src/plans.js +++ b/src/plans.js @@ -728,6 +728,7 @@ function insertJobs (schema) { priority, start_after, singleton_key, + singleton_on, dead_letter, expire_in, keep_until, @@ -743,6 +744,10 @@ function insertJobs (schema) { COALESCE(priority, 0) as priority, j.start_after, "singletonKey" as singleton_key, + CASE + WHEN "singletonSeconds" IS NOT NULL THEN 'epoch'::timestamp + '1 second'::interval * ("singletonSeconds" * floor( date_part('epoch', now()) / "singletonSeconds" )) + ELSE NULL + END as singleton_on, COALESCE("deadLetter", q.dead_letter) as dead_letter, CASE WHEN "expireInSeconds" IS NOT NULL THEN "expireInSeconds" * interval '1s' @@ -778,7 +783,7 @@ function insertJobs (schema) { "retryDelay" integer, "retryBackoff" boolean, "singletonKey" text, - "singletonOn" text, + "singletonSeconds" integer, "expireInSeconds" integer, "keepUntil" timestamp with time zone, "deadLetter" text diff --git a/src/timekeeper.js b/src/timekeeper.js index 44ef93d..bd666a0 100644 --- a/src/timekeeper.js +++ b/src/timekeeper.js @@ -60,7 +60,7 @@ class Timekeeper extends EventEmitter { batchSize: 50 } - await this.manager.work(QUEUES.SEND_IT, options, (jobs) => this.manager.insert(jobs.map(i => i.data))) + await this.manager.work(QUEUES.SEND_IT, options, async (jobs) => { await this.manager.insert(jobs.map(i => i.data)) }) setImmediate(() => this.onCron()) diff --git a/types.d.ts b/types.d.ts index 2c3395e..b9d7e63 100644 --- a/types.d.ts +++ b/types.d.ts @@ -207,6 +207,7 @@ declare namespace PgBoss { retryBackoff?: boolean; startAfter?: Date | string; singletonKey?: string; + singletonSeconds?: number; expireInSeconds?: number; keepUntil?: Date | string; deadLetter?: string;