pg-boss 10.0.2 → 10.0.3

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": "10.0.2",
3
+ "version": "10.0.3",
4
4
  "description": "Queueing jobs in Postgres from Node.js like a boss",
5
5
  "main": "./src/index.js",
6
6
  "engines": {
package/src/attorney.js CHANGED
@@ -1,7 +1,13 @@
1
1
  const assert = require('assert')
2
2
  const { DEFAULT_SCHEMA } = require('./plans')
3
3
 
4
+ const POLICY = {
5
+ MAX_EXPIRATION_HOURS: 24,
6
+ MIN_POLLING_INTERVAL_MS: 500
7
+ }
8
+
4
9
  module.exports = {
10
+ POLICY,
5
11
  getConfig,
6
12
  checkSendArgs,
7
13
  checkQueueArgs,
@@ -12,8 +18,6 @@ module.exports = {
12
18
  assertQueueName
13
19
  }
14
20
 
15
- const MAX_INTERVAL_HOURS = 24
16
-
17
21
  const WARNINGS = {
18
22
  CLOCK_SKEW: {
19
23
  message: 'Timekeeper detected clock skew between this instance and the database server. This will not affect scheduling operations, but this warning is shown any time the skew exceeds 60 seconds.',
@@ -262,7 +266,7 @@ function applyExpirationConfig (config, defaults = {}) {
262
266
  ? config.expireInSeconds
263
267
  : null
264
268
 
265
- assert(!expireIn || expireIn / 60 / 60 < MAX_INTERVAL_HOURS, `configuration assert: expiration cannot exceed ${MAX_INTERVAL_HOURS} hours`)
269
+ assert(!expireIn || expireIn / 60 / 60 < POLICY.MAX_EXPIRATION_HOURS, `configuration assert: expiration cannot exceed ${POLICY.MAX_EXPIRATION_HOURS} hours`)
266
270
 
267
271
  config.expireIn = expireIn
268
272
  config.expireInDefault = defaults?.expireIn
@@ -279,8 +283,8 @@ function applyRetryConfig (config, defaults) {
279
283
  }
280
284
 
281
285
  function applyPollingInterval (config, defaults) {
282
- assert(!('pollingIntervalSeconds' in config) || config.pollingIntervalSeconds >= 0.5,
283
- 'configuration assert: pollingIntervalSeconds must be at least every 500ms')
286
+ assert(!('pollingIntervalSeconds' in config) || config.pollingIntervalSeconds >= POLICY.MIN_POLLING_INTERVAL_MS / 1000,
287
+ `configuration assert: pollingIntervalSeconds must be at least every ${POLICY.MIN_POLLING_INTERVAL_MS}ms`)
284
288
 
285
289
  config.pollingInterval = ('pollingIntervalSeconds' in config)
286
290
  ? config.pollingIntervalSeconds * 1000
@@ -300,7 +304,8 @@ function applyMaintenanceConfig (config) {
300
304
  ? config.maintenanceIntervalSeconds
301
305
  : 120
302
306
 
303
- assert(config.maintenanceIntervalSeconds / 60 / 60 < MAX_INTERVAL_HOURS, `configuration assert: maintenance interval cannot exceed ${MAX_INTERVAL_HOURS} hours`)
307
+ assert(config.maintenanceIntervalSeconds / 60 / 60 < POLICY.MAX_EXPIRATION_HOURS,
308
+ `configuration assert: maintenance interval cannot exceed ${POLICY.MAX_EXPIRATION_HOURS} hours`)
304
309
  }
305
310
 
306
311
  function applyDeleteConfig (config) {
@@ -344,7 +349,8 @@ function applyMonitoringConfig (config) {
344
349
  : null
345
350
 
346
351
  if (config.monitorStateIntervalSeconds) {
347
- assert(config.monitorStateIntervalSeconds / 60 / 60 < MAX_INTERVAL_HOURS, `configuration assert: state monitoring interval cannot exceed ${MAX_INTERVAL_HOURS} hours`)
352
+ assert(config.monitorStateIntervalSeconds / 60 / 60 < POLICY.MAX_EXPIRATION_HOURS,
353
+ `configuration assert: state monitoring interval cannot exceed ${POLICY.MAX_EXPIRATION_HOURS} hours`)
348
354
  }
349
355
 
350
356
  const TEN_MINUTES_IN_SECONDS = 600
package/src/plans.js CHANGED
@@ -499,7 +499,7 @@ function fetchNextJob (schema) {
499
499
  WHERE name = $1
500
500
  AND state < '${JOB_STATES.active}'
501
501
  AND start_after < now()
502
- ORDER BY ${priority && 'priority desc, '} created_on, id
502
+ ORDER BY ${priority ? 'priority desc, ' : ''}created_on, id
503
503
  LIMIT $2
504
504
  FOR UPDATE SKIP LOCKED
505
505
  )
package/src/worker.js CHANGED
@@ -74,7 +74,7 @@ class Worker {
74
74
 
75
75
  this.lastJobDuration = duration
76
76
 
77
- if (!this.stopping && !this.beenNotified && (this.interval - duration > 500)) {
77
+ if (!this.stopping && !this.beenNotified && (this.interval - duration) > 100) {
78
78
  this.loopDelayPromise = delay(this.interval - duration)
79
79
  await this.loopDelayPromise
80
80
  this.loopDelayPromise = null