pg-boss 8.3.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-boss",
3
- "version": "8.3.0",
3
+ "version": "8.4.0",
4
4
  "description": "Queueing jobs in Node.js using PostgreSQL like a boss",
5
5
  "main": "./src/index.js",
6
6
  "engines": {
@@ -32,7 +32,8 @@
32
32
  "export-schema": "node ./scripts/construct.js",
33
33
  "export-migration": "node ./scripts/migrate.js",
34
34
  "export-rollback": "node ./scripts/rollback.js",
35
- "tsc": "tsc --noEmit types.d.ts"
35
+ "tsc": "tsc --noEmit types.d.ts",
36
+ "readme": "node ./test/readme.js"
36
37
  },
37
38
  "mocha": {
38
39
  "timeout": 10000,
package/src/attorney.js CHANGED
@@ -159,6 +159,7 @@ function getConfig (value) {
159
159
  applyDatabaseConfig(config)
160
160
  applyMaintenanceConfig(config)
161
161
  applyArchiveConfig(config)
162
+ applyArchiveFailedConfig(config)
162
163
  applyDeleteConfig(config)
163
164
  applyMonitoringConfig(config)
164
165
  applyUuidConfig(config)
@@ -195,6 +196,19 @@ function applyArchiveConfig (config) {
195
196
  }
196
197
  }
197
198
 
199
+ function applyArchiveFailedConfig (config) {
200
+ assert(!('archiveFailedAfterSeconds' in config) || config.archiveFailedAfterSeconds >= 1,
201
+ 'configuration assert: archiveFailedAfterSeconds must be at least every second and less than ')
202
+
203
+ config.archiveFailedSeconds = config.archiveFailedAfterSeconds || config.archiveSeconds
204
+ config.archiveFailedInterval = `${config.archiveFailedSeconds} seconds`
205
+
206
+ // Do not emit warning twice
207
+ if (config.archiveFailedSeconds < 60 && config.archiveSeconds >= 60) {
208
+ emitWarning(WARNINGS.CRON_DISABLED)
209
+ }
210
+ }
211
+
198
212
  function applyCompletionConfig (config, defaults) {
199
213
  assert(!('onComplete' in config) || config.onComplete === true || config.onComplete === false,
200
214
  'configuration assert: onComplete must be either true or false')
package/src/boss.js CHANGED
@@ -33,7 +33,7 @@ class Boss extends EventEmitter {
33
33
  this.events = events
34
34
 
35
35
  this.expireCommand = plans.locked(config.schema, plans.expire(config.schema))
36
- this.archiveCommand = plans.locked(config.schema, plans.archive(config.schema, config.archiveInterval))
36
+ this.archiveCommand = plans.locked(config.schema, plans.archive(config.schema, config.archiveInterval, config.archiveFailedInterval))
37
37
  this.purgeCommand = plans.locked(config.schema, plans.purge(config.schema, config.deleteAfter))
38
38
  this.getMaintenanceTimeCommand = plans.getMaintenanceTime(config.schema)
39
39
  this.setMaintenanceTimeCommand = plans.setMaintenanceTime(config.schema)
package/src/index.js CHANGED
@@ -170,6 +170,7 @@ class PgBoss extends EventEmitter {
170
170
  await delay(1000)
171
171
  }
172
172
 
173
+ await this.boss.stop()
173
174
  await shutdown()
174
175
  } catch (err) {
175
176
  this.emit(events.error, err)
package/src/plans.js CHANGED
@@ -601,7 +601,7 @@ function insertJobs (schema) {
601
601
  keepUntil,
602
602
  on_complete
603
603
  )
604
- SELECT
604
+ SELECT
605
605
  COALESCE(id, gen_random_uuid()) as id,
606
606
  name,
607
607
  data,
@@ -639,12 +639,16 @@ function purge (schema, interval) {
639
639
  `
640
640
  }
641
641
 
642
- function archive (schema, interval) {
642
+ function archive (schema, completedInterval, failedInterval = completedInterval) {
643
643
  return `
644
644
  WITH archived_rows AS (
645
645
  DELETE FROM ${schema}.job
646
- WHERE
647
- completedOn < (now() - interval '${interval}')
646
+ WHERE (
647
+ state <> '${states.failed}' AND completedOn < (now() - interval '${completedInterval}')
648
+ )
649
+ OR (
650
+ state = '${states.failed}' AND completedOn < (now() - interval '${failedInterval}')
651
+ )
648
652
  OR (
649
653
  state < '${states.active}' AND keepUntil < now()
650
654
  )
package/src/timekeeper.js CHANGED
@@ -45,7 +45,7 @@ class Timekeeper extends EventEmitter {
45
45
 
46
46
  async start () {
47
47
  // setting the archive config too low breaks the cron 60s debounce interval so don't even try
48
- if (this.config.archiveSeconds < 60) {
48
+ if (this.config.archiveSeconds < 60 || this.config.archiveFailedSeconds < 60) {
49
49
  return
50
50
  }
51
51
 
package/types.d.ts CHANGED
@@ -44,6 +44,7 @@ declare namespace PgBoss {
44
44
  maintenanceIntervalMinutes?: number;
45
45
 
46
46
  archiveCompletedAfterSeconds?: number;
47
+ archiveFailedAfterSeconds?: number;
47
48
  }
48
49
 
49
50
  type ConstructorOptions =