pg-boss 7.0.3 → 7.2.1
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 +1 -0
- package/package.json +1 -1
- package/src/index.js +8 -8
- package/src/manager.js +8 -0
- package/src/plans.js +14 -0
- package/types.d.ts +4 -0
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ pg-boss relies on [SKIP LOCKED](http://blog.2ndquadrant.com/what-is-select-skip-
|
|
|
38
38
|
This will likely cater the most to teams already familiar with the simplicity of relational database semantics and operations (SQL, querying, and backups). It will be especially useful to those already relying on PostgreSQL that want to limit how many systems are required to monitor and support in their architecture.
|
|
39
39
|
|
|
40
40
|
## Features
|
|
41
|
+
* Exactly-once job delivery
|
|
41
42
|
* Backpressure-compatible polling workers
|
|
42
43
|
* Cron scheduling
|
|
43
44
|
* Pub/sub API for fan-out queue relationships
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -73,12 +73,14 @@ class PgBoss extends EventEmitter {
|
|
|
73
73
|
|
|
74
74
|
function promoteFunction (obj, func) {
|
|
75
75
|
this[func.name] = (...args) => {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const shouldRun = !this.started || !((func.name === 'work' || func.name === 'onComplete') && (this.stopped || this.stoppingOn))
|
|
77
|
+
|
|
78
|
+
if (shouldRun) {
|
|
79
|
+
return func.apply(obj, args)
|
|
80
|
+
} else {
|
|
81
|
+
const state = this.stoppingOn ? 'stopping' : this.stopped ? 'stopped' : !this.started ? 'not started' : 'started'
|
|
78
82
|
return Promise.reject(new Error(`pg-boss is ${state}.`))
|
|
79
83
|
}
|
|
80
|
-
|
|
81
|
-
return func.apply(obj, args)
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -100,6 +102,8 @@ class PgBoss extends EventEmitter {
|
|
|
100
102
|
|
|
101
103
|
await this.contractor.start()
|
|
102
104
|
|
|
105
|
+
this.started = true
|
|
106
|
+
|
|
103
107
|
this.manager.start()
|
|
104
108
|
|
|
105
109
|
if (!this.config.noSupervisor) {
|
|
@@ -132,10 +136,6 @@ class PgBoss extends EventEmitter {
|
|
|
132
136
|
await this.timekeeper.stop()
|
|
133
137
|
|
|
134
138
|
const shutdown = async () => {
|
|
135
|
-
if (this.db.isOurs) {
|
|
136
|
-
await this.db.close()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
139
|
this.stopped = true
|
|
140
140
|
this.stoppingOn = null
|
|
141
141
|
|
package/src/manager.js
CHANGED
|
@@ -56,6 +56,7 @@ class Manager extends EventEmitter {
|
|
|
56
56
|
this.insertJobsCommand = plans.insertJobs(config.schema)
|
|
57
57
|
this.completeJobsCommand = plans.completeJobs(config.schema)
|
|
58
58
|
this.cancelJobsCommand = plans.cancelJobs(config.schema)
|
|
59
|
+
this.resumeJobsCommand = plans.resumeJobs(config.schema)
|
|
59
60
|
this.failJobsCommand = plans.failJobs(config.schema)
|
|
60
61
|
this.getJobByIdCommand = plans.getJobById(config.schema)
|
|
61
62
|
this.getArchivedJobByIdCommand = plans.getArchivedJobById(config.schema)
|
|
@@ -67,6 +68,7 @@ class Manager extends EventEmitter {
|
|
|
67
68
|
this.functions = [
|
|
68
69
|
this.complete,
|
|
69
70
|
this.cancel,
|
|
71
|
+
this.resume,
|
|
70
72
|
this.fail,
|
|
71
73
|
this.fetch,
|
|
72
74
|
this.fetchCompleted,
|
|
@@ -541,6 +543,12 @@ class Manager extends EventEmitter {
|
|
|
541
543
|
return this.mapCompletionResponse(ids, result)
|
|
542
544
|
}
|
|
543
545
|
|
|
546
|
+
async resume (id) {
|
|
547
|
+
const ids = this.mapCompletionIdArg(id, 'resume')
|
|
548
|
+
const result = await this.db.executeSql(this.resumeJobsCommand, [ids])
|
|
549
|
+
return this.mapCompletionResponse(ids, result)
|
|
550
|
+
}
|
|
551
|
+
|
|
544
552
|
async deleteQueue (queue, options) {
|
|
545
553
|
assert(queue, 'Missing queue name argument')
|
|
546
554
|
const sql = plans.deleteQueue(this.config.schema, options)
|
package/src/plans.js
CHANGED
|
@@ -26,6 +26,7 @@ module.exports = {
|
|
|
26
26
|
fetchNextJob,
|
|
27
27
|
completeJobs,
|
|
28
28
|
cancelJobs,
|
|
29
|
+
resumeJobs,
|
|
29
30
|
failJobs,
|
|
30
31
|
insertJob,
|
|
31
32
|
insertJobs,
|
|
@@ -497,6 +498,19 @@ function cancelJobs (schema) {
|
|
|
497
498
|
`
|
|
498
499
|
}
|
|
499
500
|
|
|
501
|
+
function resumeJobs (schema) {
|
|
502
|
+
return `
|
|
503
|
+
with results as (
|
|
504
|
+
UPDATE ${schema}.job
|
|
505
|
+
SET completedOn = NULL,
|
|
506
|
+
state = '${states.created}'
|
|
507
|
+
WHERE id IN (SELECT UNNEST($1::uuid[]))
|
|
508
|
+
RETURNING 1
|
|
509
|
+
)
|
|
510
|
+
SELECT COUNT(*) from results
|
|
511
|
+
`
|
|
512
|
+
}
|
|
513
|
+
|
|
500
514
|
function insertJob (schema) {
|
|
501
515
|
return `
|
|
502
516
|
INSERT INTO ${schema}.job (
|
package/types.d.ts
CHANGED
|
@@ -102,6 +102,7 @@ declare namespace PgBoss {
|
|
|
102
102
|
interface JobFetchOptions {
|
|
103
103
|
teamSize?: number;
|
|
104
104
|
teamConcurrency?: number;
|
|
105
|
+
teamRefill?: boolean;
|
|
105
106
|
batchSize?: number;
|
|
106
107
|
includeMetadata?: boolean;
|
|
107
108
|
}
|
|
@@ -329,6 +330,9 @@ declare class PgBoss extends EventEmitter {
|
|
|
329
330
|
cancel(id: string): Promise<void>;
|
|
330
331
|
cancel(ids: string[]): Promise<void>;
|
|
331
332
|
|
|
333
|
+
resume(id: string): Promise<void>;
|
|
334
|
+
resume(ids: string[]): Promise<void>;
|
|
335
|
+
|
|
332
336
|
complete(id: string): Promise<void>;
|
|
333
337
|
complete(id: string, data: object): Promise<void>;
|
|
334
338
|
complete(ids: string[]): Promise<void>;
|