pg-boss 7.0.0 → 7.1.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/README.md +8 -9
- package/package.json +4 -2
- package/src/index.js +8 -8
- package/types.d.ts +21 -14
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@ Queueing jobs in Node.js using PostgreSQL like a boss.
|
|
|
2
2
|
|
|
3
3
|
[](http://www.postgresql.org)
|
|
4
4
|
[](https://badge.fury.io/js/pg-boss)
|
|
5
|
-
[](https://travis-ci.com/timgit/pg-boss)
|
|
5
|
+
[](https://app.travis-ci.com/github/timgit/pg-boss)
|
|
6
6
|
[](https://coveralls.io/github/timgit/pg-boss?branch=master)
|
|
7
7
|
|
|
8
8
|
```js
|
|
@@ -33,20 +33,19 @@ async function someAsyncJobHandler(job) {
|
|
|
33
33
|
|
|
34
34
|
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.
|
|
35
35
|
|
|
36
|
-
pg-boss relies on [SKIP LOCKED](http://blog.2ndquadrant.com/what-is-select-skip-locked-for-in-postgresql-9-5), a feature
|
|
36
|
+
pg-boss relies on [SKIP LOCKED](http://blog.2ndquadrant.com/what-is-select-skip-locked-for-in-postgresql-9-5), a feature added to postgres specifically for message queues, in order to resolve record locking challenges inherent with relational databases. This brings the safety of guaranteed atomic commits of a relational database to your asynchronous job processing.
|
|
37
37
|
|
|
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
|
-
* Backpressure-compatible
|
|
42
|
-
*
|
|
41
|
+
* Backpressure-compatible polling workers
|
|
42
|
+
* Cron scheduling
|
|
43
43
|
* Pub/sub API for fan-out queue relationships
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* Direct send, fetch and completion APIs for custom integrations
|
|
44
|
+
* Deferral, retries (with exponential backoff), rate limiting, debouncing
|
|
45
|
+
* Completion jobs for orchestrations/sagas
|
|
47
46
|
* Direct table access for bulk loads via COPY or INSERT
|
|
48
|
-
* Multi-master compatible
|
|
49
|
-
* Automatic
|
|
47
|
+
* Multi-master compatible (for example, in a Kubernetes ReplicaSet)
|
|
48
|
+
* Automatic creation and migration of storage tables
|
|
50
49
|
* Automatic maintenance operations to manage table growth
|
|
51
50
|
|
|
52
51
|
## Requirements
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-boss",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Queueing jobs in Node.js using PostgreSQL like a boss",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"uuid": "^8.3.2"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
+
"@types/node": "^17.0.2",
|
|
18
19
|
"coveralls": "^3.1.0",
|
|
19
20
|
"luxon": "^2.0.1",
|
|
20
21
|
"mocha": "^9.0.1",
|
|
@@ -27,7 +28,8 @@
|
|
|
27
28
|
"forcover": "npm run cover && nyc report --reporter=text-lcov | coveralls",
|
|
28
29
|
"export-schema": "node ./scripts/construct.js",
|
|
29
30
|
"export-migration": "node ./scripts/migrate.js",
|
|
30
|
-
"export-rollback": "node ./scripts/rollback.js"
|
|
31
|
+
"export-rollback": "node ./scripts/rollback.js",
|
|
32
|
+
"tsc": "tsc --noEmit types.d.ts"
|
|
31
33
|
},
|
|
32
34
|
"mocha": {
|
|
33
35
|
"timeout": 10000,
|
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/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { EventEmitter } from 'events'
|
|
2
|
+
|
|
1
3
|
declare namespace PgBoss {
|
|
2
4
|
interface Db {
|
|
3
5
|
executeSql(text: string, values: any[]): Promise<{ rows: any[]; rowCount: number }>;
|
|
@@ -201,7 +203,7 @@ declare namespace PgBoss {
|
|
|
201
203
|
done: JobDoneCallback<ResData>;
|
|
202
204
|
}
|
|
203
205
|
|
|
204
|
-
interface
|
|
206
|
+
interface MonitorState {
|
|
205
207
|
all: number;
|
|
206
208
|
created: number;
|
|
207
209
|
retry: number;
|
|
@@ -210,7 +212,10 @@ declare namespace PgBoss {
|
|
|
210
212
|
expired: number;
|
|
211
213
|
cancelled: number;
|
|
212
214
|
failed: number;
|
|
213
|
-
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface MonitorStates extends MonitorState {
|
|
218
|
+
queues: { [queueName: string]: MonitorState };
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
interface Worker {
|
|
@@ -239,7 +244,7 @@ declare namespace PgBoss {
|
|
|
239
244
|
|
|
240
245
|
}
|
|
241
246
|
|
|
242
|
-
declare class PgBoss {
|
|
247
|
+
declare class PgBoss extends EventEmitter {
|
|
243
248
|
constructor(connectionString: string);
|
|
244
249
|
constructor(options: PgBoss.ConstructorOptions);
|
|
245
250
|
|
|
@@ -254,20 +259,20 @@ declare class PgBoss {
|
|
|
254
259
|
static getRollbackPlans(schema: string): string;
|
|
255
260
|
static getRollbackPlans(): string;
|
|
256
261
|
|
|
257
|
-
on(event: "error", handler: (error: Error) => void):
|
|
258
|
-
off(event: "error", handler: (error: Error) => void):
|
|
262
|
+
on(event: "error", handler: (error: Error) => void): this;
|
|
263
|
+
off(event: "error", handler: (error: Error) => void): this;
|
|
259
264
|
|
|
260
|
-
on(event: "maintenance", handler: () => void):
|
|
261
|
-
off(event: "maintenance", handler: () => void):
|
|
265
|
+
on(event: "maintenance", handler: () => void): this;
|
|
266
|
+
off(event: "maintenance", handler: () => void): this;
|
|
262
267
|
|
|
263
|
-
on(event: "monitor-states", handler: (monitorStates: PgBoss.MonitorStates) => void):
|
|
264
|
-
off(event: "monitor-states", handler: (monitorStates: PgBoss.MonitorStates) => void):
|
|
268
|
+
on(event: "monitor-states", handler: (monitorStates: PgBoss.MonitorStates) => void): this;
|
|
269
|
+
off(event: "monitor-states", handler: (monitorStates: PgBoss.MonitorStates) => void): this;
|
|
265
270
|
|
|
266
|
-
on(event: "wip", handler: (data: PgBoss.Worker[]) => void):
|
|
267
|
-
off(event: "wip", handler: (data: PgBoss.Worker[]) => void):
|
|
271
|
+
on(event: "wip", handler: (data: PgBoss.Worker[]) => void): this;
|
|
272
|
+
off(event: "wip", handler: (data: PgBoss.Worker[]) => void): this;
|
|
268
273
|
|
|
269
|
-
on(event: "stopped", handler: () => void):
|
|
270
|
-
off(event: "stopped", handler: () => void):
|
|
274
|
+
on(event: "stopped", handler: () => void): this;
|
|
275
|
+
off(event: "stopped", handler: () => void): this;
|
|
271
276
|
|
|
272
277
|
start(): Promise<PgBoss>;
|
|
273
278
|
stop(options?: PgBoss.StopOptions): Promise<void>;
|
|
@@ -304,7 +309,9 @@ declare class PgBoss {
|
|
|
304
309
|
|
|
305
310
|
subscribe(event: string, name: string): Promise<void>;
|
|
306
311
|
unsubscribe(event: string, name: string): Promise<void>;
|
|
307
|
-
publish(
|
|
312
|
+
publish(event: string): Promise<string[]>;
|
|
313
|
+
publish(event: string, data: object): Promise<string[]>;
|
|
314
|
+
publish(event: string, data: object, options: PgBoss.SendOptions): Promise<string[]>;
|
|
308
315
|
|
|
309
316
|
offComplete(name: string): Promise<void>;
|
|
310
317
|
offComplete(options: PgBoss.OffWorkOptions): Promise<void>;
|