pg-boss 10.0.2 → 10.0.4
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/README.md +6 -0
- package/package.json +1 -1
- package/src/attorney.js +13 -7
- package/src/plans.js +12 -2
- package/src/worker.js +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,12 @@ async function readme() {
|
|
|
25
25
|
console.log(`received job ${job.id} with data ${JSON.stringify(job.data)}`)
|
|
26
26
|
})
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
readme()
|
|
30
|
+
.catch(err => {
|
|
31
|
+
console.log(err)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
})
|
|
28
34
|
```
|
|
29
35
|
|
|
30
36
|
pg-boss is a job queue built in Node.js on top of PostgreSQL in order to provide background processing and reliable asynchronous execution to Node.js applications.
|
package/package.json
CHANGED
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 <
|
|
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 >=
|
|
283
|
-
|
|
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 <
|
|
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 <
|
|
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
|
@@ -226,8 +226,10 @@ function createQueueFunction (schema) {
|
|
|
226
226
|
$$
|
|
227
227
|
DECLARE
|
|
228
228
|
table_name varchar := 'j' || encode(sha224(queue_name::bytea), 'hex');
|
|
229
|
+
queue_created_on timestamptz;
|
|
229
230
|
BEGIN
|
|
230
231
|
|
|
232
|
+
WITH q as (
|
|
231
233
|
INSERT INTO ${schema}.queue (
|
|
232
234
|
name,
|
|
233
235
|
policy,
|
|
@@ -249,7 +251,15 @@ function createQueueFunction (schema) {
|
|
|
249
251
|
(options->>'retentionMinutes')::int,
|
|
250
252
|
options->>'deadLetter',
|
|
251
253
|
table_name
|
|
252
|
-
)
|
|
254
|
+
)
|
|
255
|
+
ON CONFLICT DO NOTHING
|
|
256
|
+
RETURNING created_on
|
|
257
|
+
)
|
|
258
|
+
SELECT created_on into queue_created_on from q;
|
|
259
|
+
|
|
260
|
+
IF queue_created_on IS NULL THEN
|
|
261
|
+
RETURN;
|
|
262
|
+
END IF;
|
|
253
263
|
|
|
254
264
|
EXECUTE format('CREATE TABLE ${schema}.%I (LIKE ${schema}.job INCLUDING DEFAULTS)', table_name);
|
|
255
265
|
|
|
@@ -499,7 +509,7 @@ function fetchNextJob (schema) {
|
|
|
499
509
|
WHERE name = $1
|
|
500
510
|
AND state < '${JOB_STATES.active}'
|
|
501
511
|
AND start_after < now()
|
|
502
|
-
ORDER BY ${priority
|
|
512
|
+
ORDER BY ${priority ? 'priority desc, ' : ''}created_on, id
|
|
503
513
|
LIMIT $2
|
|
504
514
|
FOR UPDATE SKIP LOCKED
|
|
505
515
|
)
|
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 >
|
|
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
|