pg-boss 7.2.1 → 7.3.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/package.json +1 -1
- package/src/manager.js +7 -0
- package/src/worker.js +11 -1
- package/types.d.ts +6 -0
package/package.json
CHANGED
package/src/manager.js
CHANGED
|
@@ -74,6 +74,7 @@ class Manager extends EventEmitter {
|
|
|
74
74
|
this.fetchCompleted,
|
|
75
75
|
this.work,
|
|
76
76
|
this.offWork,
|
|
77
|
+
this.notifyWorker,
|
|
77
78
|
this.onComplete,
|
|
78
79
|
this.offComplete,
|
|
79
80
|
this.publish,
|
|
@@ -294,6 +295,12 @@ class Manager extends EventEmitter {
|
|
|
294
295
|
})
|
|
295
296
|
}
|
|
296
297
|
|
|
298
|
+
notifyWorker (workerId) {
|
|
299
|
+
if (this.workers.has(workerId)) {
|
|
300
|
+
this.workers.get(workerId).notify()
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
297
304
|
async subscribe (event, name) {
|
|
298
305
|
assert(event, 'Missing required argument')
|
|
299
306
|
assert(name, 'Missing required argument')
|
package/src/worker.js
CHANGED
|
@@ -27,6 +27,15 @@ class Worker {
|
|
|
27
27
|
this.stopping = false
|
|
28
28
|
this.stopped = false
|
|
29
29
|
this.loopDelayPromise = null
|
|
30
|
+
this.beenNotified = false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
notify () {
|
|
34
|
+
this.beenNotified = true
|
|
35
|
+
|
|
36
|
+
if (this.loopDelayPromise) {
|
|
37
|
+
this.loopDelayPromise.clear()
|
|
38
|
+
}
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
async start () {
|
|
@@ -36,6 +45,7 @@ class Worker {
|
|
|
36
45
|
const started = Date.now()
|
|
37
46
|
|
|
38
47
|
try {
|
|
48
|
+
this.beenNotified = false
|
|
39
49
|
const jobs = await this.fetch()
|
|
40
50
|
|
|
41
51
|
this.lastFetchedOn = Date.now()
|
|
@@ -64,7 +74,7 @@ class Worker {
|
|
|
64
74
|
|
|
65
75
|
this.lastJobDuration = duration
|
|
66
76
|
|
|
67
|
-
if (!this.stopping && duration < this.interval) {
|
|
77
|
+
if (!this.stopping && !this.beenNotified && duration < this.interval) {
|
|
68
78
|
this.loopDelayPromise = delay(this.interval - duration)
|
|
69
79
|
await this.loopDelayPromise
|
|
70
80
|
this.loopDelayPromise = null
|
package/types.d.ts
CHANGED
|
@@ -308,6 +308,12 @@ declare class PgBoss extends EventEmitter {
|
|
|
308
308
|
offWork(name: string): Promise<void>;
|
|
309
309
|
offWork(options: PgBoss.OffWorkOptions): Promise<void>;
|
|
310
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Notify worker that something has changed
|
|
313
|
+
* @param workerId
|
|
314
|
+
*/
|
|
315
|
+
notifyWorker(workerId: string): void;
|
|
316
|
+
|
|
311
317
|
subscribe(event: string, name: string): Promise<void>;
|
|
312
318
|
unsubscribe(event: string, name: string): Promise<void>;
|
|
313
319
|
publish(event: string): Promise<string[]>;
|