pg-boss 10.0.1 → 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/README.md +3 -0
- package/package.json +1 -1
- package/src/attorney.js +13 -7
- package/src/plans.js +1 -1
- package/src/worker.js +1 -1
- package/types.d.ts +8 -8
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ async function readme() {
|
|
|
15
15
|
|
|
16
16
|
const queue = 'readme-queue'
|
|
17
17
|
|
|
18
|
+
await boss.createQueue(queue)
|
|
19
|
+
|
|
18
20
|
const id = await boss.send(queue, { arg1: 'read me' })
|
|
19
21
|
|
|
20
22
|
console.log(`created job ${id} in queue ${queue}`)
|
|
@@ -34,6 +36,7 @@ This will likely cater the most to teams already familiar with the simplicity of
|
|
|
34
36
|
|
|
35
37
|
## Summary
|
|
36
38
|
* Exactly-once job delivery
|
|
39
|
+
* Create jobs within your existing database transaction
|
|
37
40
|
* Backpressure-compatible polling workers
|
|
38
41
|
* Cron scheduling
|
|
39
42
|
* Queue storage policies to support a variety of rate limiting, debouncing, and concurrency use cases
|
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
|
@@ -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
|
|
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 >
|
|
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
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'events'
|
|
2
2
|
|
|
3
3
|
declare namespace PgBoss {
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
type JobStates = {
|
|
6
6
|
created : 'created',
|
|
7
7
|
retry: 'retry',
|
|
@@ -107,13 +107,13 @@ declare namespace PgBoss {
|
|
|
107
107
|
interface ConnectionOptions {
|
|
108
108
|
db?: Db;
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
type InsertOptions = ConnectionOptions;
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
type SendOptions = JobOptions & ExpirationOptions & RetentionOptions & RetryOptions & ConnectionOptions;
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
type QueuePolicy = 'standard' | 'short' | 'singleton' | 'stately'
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
type Queue = RetryOptions & ExpirationOptions & RetentionOptions & { name: string, policy?: QueuePolicy, deadLetter?: string }
|
|
118
118
|
type QueueResult = Queue & { createdOn: Date, updatedOn: Date }
|
|
119
119
|
type ScheduleOptions = SendOptions & { tz?: string }
|
|
@@ -334,7 +334,7 @@ declare class PgBoss extends EventEmitter {
|
|
|
334
334
|
|
|
335
335
|
deleteJob(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
|
|
336
336
|
deleteJob(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
|
|
337
|
-
|
|
337
|
+
|
|
338
338
|
complete(name: string, id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
|
|
339
339
|
complete(name: string, id: string, data: object, options?: PgBoss.ConnectionOptions): Promise<void>;
|
|
340
340
|
complete(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
|
|
@@ -343,8 +343,8 @@ declare class PgBoss extends EventEmitter {
|
|
|
343
343
|
fail(name: string, id: string, data: object, options?: PgBoss.ConnectionOptions): Promise<void>;
|
|
344
344
|
fail(name: string, ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
|
|
345
345
|
|
|
346
|
-
getJobById(name: string, id: string, options?: PgBoss.ConnectionOptions & { includeArchive:
|
|
347
|
-
|
|
346
|
+
getJobById<T>(name: string, id: string, options?: PgBoss.ConnectionOptions & { includeArchive: boolean }): Promise<PgBoss.JobWithMetadata<T> | null>;
|
|
347
|
+
|
|
348
348
|
createQueue(name: string, options?: PgBoss.Queue): Promise<void>;
|
|
349
349
|
updateQueue(name: string, options?: PgBoss.Queue): Promise<void>;
|
|
350
350
|
deleteQueue(name: string): Promise<void>;
|