pg-boss 10.0.0-beta14 → 10.0.0-beta15
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 -2
- package/src/manager.js +7 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-boss",
|
|
3
|
-
"version": "10.0.0-
|
|
3
|
+
"version": "10.0.0-beta15",
|
|
4
4
|
"description": "Queueing jobs in Postgres from Node.js like a boss",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"cron-parser": "^4.0.0",
|
|
11
|
-
"lodash.debounce": "^4.0.8",
|
|
12
11
|
"p-map": "^4.0.0",
|
|
13
12
|
"pg": "^8.5.1",
|
|
14
13
|
"serialize-error": "^8.1.0"
|
package/src/manager.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const assert = require('assert')
|
|
2
2
|
const EventEmitter = require('events')
|
|
3
3
|
const { randomUUID } = require('crypto')
|
|
4
|
-
const debounce = require('lodash.debounce')
|
|
5
4
|
const { serializeError: stringify } = require('serialize-error')
|
|
6
5
|
const pMap = require('p-map')
|
|
7
6
|
const { delay } = require('./tools')
|
|
@@ -14,9 +13,6 @@ const { QUEUE_POLICIES } = plans
|
|
|
14
13
|
|
|
15
14
|
const INTERNAL_QUEUES = Object.values(TIMEKEEPER_QUEUES).reduce((acc, i) => ({ ...acc, [i]: i }), {})
|
|
16
15
|
|
|
17
|
-
const WIP_EVENT_INTERVAL = 2000
|
|
18
|
-
const WIP_DEBOUNCE_OPTIONS = { leading: true, trailing: true, maxWait: WIP_EVENT_INTERVAL }
|
|
19
|
-
|
|
20
16
|
const events = {
|
|
21
17
|
error: 'error',
|
|
22
18
|
wip: 'wip'
|
|
@@ -45,6 +41,7 @@ class Manager extends EventEmitter {
|
|
|
45
41
|
this.db = db
|
|
46
42
|
|
|
47
43
|
this.events = events
|
|
44
|
+
this.wipTs = Date.now()
|
|
48
45
|
this.workers = new Map()
|
|
49
46
|
|
|
50
47
|
this.nextJobCommand = plans.fetchNextJob(config.schema)
|
|
@@ -97,8 +94,6 @@ class Manager extends EventEmitter {
|
|
|
97
94
|
this.clearStorage,
|
|
98
95
|
this.getJobById
|
|
99
96
|
]
|
|
100
|
-
|
|
101
|
-
this.emitWipThrottled = debounce(() => this.emit(events.wip, this.getWipData()), WIP_EVENT_INTERVAL, WIP_DEBOUNCE_OPTIONS)
|
|
102
97
|
}
|
|
103
98
|
|
|
104
99
|
start () {
|
|
@@ -143,7 +138,12 @@ class Manager extends EventEmitter {
|
|
|
143
138
|
|
|
144
139
|
emitWip (name) {
|
|
145
140
|
if (!INTERNAL_QUEUES[name]) {
|
|
146
|
-
|
|
141
|
+
const now = Date.now()
|
|
142
|
+
|
|
143
|
+
if (now - this.wipTs > 2000) {
|
|
144
|
+
this.emit(events.wip, this.getWipData())
|
|
145
|
+
this.wipTs = now
|
|
146
|
+
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|