qdone 2.0.33-alpha → 2.0.35-alpha
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/commonjs/src/consumer.js
CHANGED
|
@@ -61,7 +61,7 @@ async function processMessages(queues, callback, options) {
|
|
|
61
61
|
lastLatency = latency;
|
|
62
62
|
});
|
|
63
63
|
const jobExecutor = new jobExecutor_js_1.JobExecutor(opt);
|
|
64
|
-
const queueManager = new queueManager_js_1.QueueManager(opt, queues,
|
|
64
|
+
const queueManager = new queueManager_js_1.QueueManager(opt, queues, 10);
|
|
65
65
|
const cores = (0, os_1.cpus)().length;
|
|
66
66
|
// debug({ systemMonitor, jobExecutor, queueManager })
|
|
67
67
|
// This delay function keeps a timeout reference around so it can be
|
|
@@ -101,8 +101,7 @@ async function processMessages(queues, callback, options) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
// Max job accounting
|
|
104
|
-
|
|
105
|
-
maxReturnCount -= messages.length;
|
|
104
|
+
maxReturnCount -= maxMessages;
|
|
106
105
|
activeQrls.delete(qrl);
|
|
107
106
|
}
|
|
108
107
|
catch (e) {
|
|
@@ -117,7 +116,8 @@ async function processMessages(queues, callback, options) {
|
|
|
117
116
|
};
|
|
118
117
|
while (!shutdownRequested) { // eslint-disable-line
|
|
119
118
|
// Figure out how we are running
|
|
120
|
-
const
|
|
119
|
+
const runningJobs = jobExecutor.runningJobCount();
|
|
120
|
+
const allowedJobs = Math.max(0, opt.maxConcurrentJobs - maxReturnCount - runningJobs);
|
|
121
121
|
// Latency
|
|
122
122
|
const maxLatency = 100;
|
|
123
123
|
const latency = systemMonitor.getLatency() || 10;
|
|
@@ -137,12 +137,14 @@ async function processMessages(queues, callback, options) {
|
|
|
137
137
|
const targetJobs = Math.round(allowedJobs * overallFactor);
|
|
138
138
|
let jobsLeft = targetJobs;
|
|
139
139
|
if (opt.verbose) {
|
|
140
|
-
|
|
140
|
+
console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, maxReturnCount, runningJobs, allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs, activeQrls });
|
|
141
141
|
}
|
|
142
142
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
143
143
|
// const qcount = jobExecutor.runningJobCountForQueue(qname)
|
|
144
144
|
// console.log({ evaluating: { qname, qrl, qcount, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
145
|
-
if (jobsLeft <= 0
|
|
145
|
+
if (jobsLeft <= 0)
|
|
146
|
+
break;
|
|
147
|
+
if (activeQrls.has(qrl))
|
|
146
148
|
continue;
|
|
147
149
|
const maxMessages = Math.min(10, jobsLeft);
|
|
148
150
|
listen(qname, qrl, maxMessages);
|
package/commonjs/src/defaults.js
CHANGED
|
@@ -20,6 +20,7 @@ exports.defaults = Object.freeze({
|
|
|
20
20
|
fifo: false,
|
|
21
21
|
disableLog: false,
|
|
22
22
|
includeFailed: false,
|
|
23
|
+
includeDead: false,
|
|
23
24
|
// Enqueue
|
|
24
25
|
groupId: (0, uuid_1.v1)(),
|
|
25
26
|
groupIdPerMessage: false,
|
|
@@ -73,6 +74,8 @@ function getOptionsWithDefaults(options) {
|
|
|
73
74
|
fifo: options.fifo || exports.defaults.fifo,
|
|
74
75
|
sentryDsn: options.sentryDsn || options['sentry-dsn'],
|
|
75
76
|
disableLog: options.disableLog || options['disable-log'] || exports.defaults.disableLog,
|
|
77
|
+
includeFailed: options.includeFailed || options['include-failed'] || exports.defaults.includeFailed,
|
|
78
|
+
includeDead: options.includeDead || options['include-dead'] || exports.defaults.includeDead,
|
|
76
79
|
// Cache
|
|
77
80
|
cacheUri: options.cacheUri || options['cache-uri'] || exports.defaults.cacheUri,
|
|
78
81
|
cachePrefix: options.cachePrefix || options['cache-prefix'] || exports.defaults.cachePrefix,
|
|
@@ -94,7 +97,6 @@ function getOptionsWithDefaults(options) {
|
|
|
94
97
|
killAfter: options.killAfter || options['kill-after'] || exports.defaults.killAfter,
|
|
95
98
|
archive: options.archive || exports.defaults.archive,
|
|
96
99
|
activeOnly: options.activeOnly || options['active-only'] || exports.defaults.activeOnly,
|
|
97
|
-
includeFailed: options.includeFailed || options['include-failed'] || exports.defaults.includeFailed,
|
|
98
100
|
maxConcurrentJobs: options.maxConcurrentJobs || exports.defaults.maxConcurrentJobs,
|
|
99
101
|
maxMemoryPercent: options.maxMemoryPercent || exports.defaults.maxMemoryPercent,
|
|
100
102
|
// Idle Queues
|
|
@@ -105,7 +105,7 @@ class QueueManager {
|
|
|
105
105
|
.filter(({ qname, qrl }) => {
|
|
106
106
|
const isFifo = qname.endsWith('.fifo');
|
|
107
107
|
const isDead = isFifo ? qname.endsWith('_dead.fifo') : qname.endsWith('_dead');
|
|
108
|
-
return !isDead;
|
|
108
|
+
return this.opt.includeDead ? true : !isDead;
|
|
109
109
|
})
|
|
110
110
|
// then icehouse
|
|
111
111
|
.filter(({ qname, qrl }) => !this.keepInIcehouse(qrl, now));
|
|
@@ -146,6 +146,7 @@ class QueueManager {
|
|
|
146
146
|
}
|
|
147
147
|
getPairs() {
|
|
148
148
|
const now = new Date();
|
|
149
|
+
this.selectedPairs.sort(() => 0.5 - Math.random());
|
|
149
150
|
return this.selectedPairs.filter(({ qname, qrl }) => !this.keepInIcehouse(qrl, now));
|
|
150
151
|
}
|
|
151
152
|
async shutdown() {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qdone",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.35-alpha",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "qdone",
|
|
9
|
-
"version": "2.0.
|
|
9
|
+
"version": "2.0.35-alpha",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cloudwatch": "3.465.0",
|
package/package.json
CHANGED
package/src/consumer.js
CHANGED
|
@@ -61,7 +61,7 @@ export async function processMessages (queues, callback, options) {
|
|
|
61
61
|
lastLatency = latency
|
|
62
62
|
})
|
|
63
63
|
const jobExecutor = new JobExecutor(opt)
|
|
64
|
-
const queueManager = new QueueManager(opt, queues,
|
|
64
|
+
const queueManager = new QueueManager(opt, queues, 10)
|
|
65
65
|
const cores = cpus().length
|
|
66
66
|
// debug({ systemMonitor, jobExecutor, queueManager })
|
|
67
67
|
|
|
@@ -105,7 +105,7 @@ export async function processMessages (queues, callback, options) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// Max job accounting
|
|
108
|
-
|
|
108
|
+
maxReturnCount -= maxMessages
|
|
109
109
|
activeQrls.delete(qrl)
|
|
110
110
|
} catch (e) {
|
|
111
111
|
// If the queue has been cleaned up, we should back off anyway
|
|
@@ -119,7 +119,8 @@ export async function processMessages (queues, callback, options) {
|
|
|
119
119
|
|
|
120
120
|
while (!shutdownRequested) { // eslint-disable-line
|
|
121
121
|
// Figure out how we are running
|
|
122
|
-
const
|
|
122
|
+
const runningJobs = jobExecutor.runningJobCount()
|
|
123
|
+
const allowedJobs = Math.max(0, opt.maxConcurrentJobs - maxReturnCount - runningJobs)
|
|
123
124
|
|
|
124
125
|
// Latency
|
|
125
126
|
const maxLatency = 100
|
|
@@ -144,12 +145,13 @@ export async function processMessages (queues, callback, options) {
|
|
|
144
145
|
let jobsLeft = targetJobs
|
|
145
146
|
|
|
146
147
|
if (opt.verbose) {
|
|
147
|
-
|
|
148
|
+
console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, maxReturnCount, runningJobs, allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs, activeQrls })
|
|
148
149
|
}
|
|
149
150
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
150
151
|
// const qcount = jobExecutor.runningJobCountForQueue(qname)
|
|
151
152
|
// console.log({ evaluating: { qname, qrl, qcount, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
152
|
-
if (jobsLeft <= 0
|
|
153
|
+
if (jobsLeft <= 0) break
|
|
154
|
+
if (activeQrls.has(qrl)) continue
|
|
153
155
|
const maxMessages = Math.min(10, jobsLeft)
|
|
154
156
|
listen(qname, qrl, maxMessages)
|
|
155
157
|
jobsLeft -= maxMessages
|
package/src/defaults.js
CHANGED
|
@@ -18,6 +18,7 @@ export const defaults = Object.freeze({
|
|
|
18
18
|
fifo: false,
|
|
19
19
|
disableLog: false,
|
|
20
20
|
includeFailed: false,
|
|
21
|
+
includeDead: false,
|
|
21
22
|
|
|
22
23
|
// Enqueue
|
|
23
24
|
groupId: uuidv1(),
|
|
@@ -76,6 +77,8 @@ export function getOptionsWithDefaults (options) {
|
|
|
76
77
|
fifo: options.fifo || defaults.fifo,
|
|
77
78
|
sentryDsn: options.sentryDsn || options['sentry-dsn'],
|
|
78
79
|
disableLog: options.disableLog || options['disable-log'] || defaults.disableLog,
|
|
80
|
+
includeFailed: options.includeFailed || options['include-failed'] || defaults.includeFailed,
|
|
81
|
+
includeDead: options.includeDead || options['include-dead'] || defaults.includeDead,
|
|
79
82
|
|
|
80
83
|
// Cache
|
|
81
84
|
cacheUri: options.cacheUri || options['cache-uri'] || defaults.cacheUri,
|
|
@@ -100,7 +103,6 @@ export function getOptionsWithDefaults (options) {
|
|
|
100
103
|
killAfter: options.killAfter || options['kill-after'] || defaults.killAfter,
|
|
101
104
|
archive: options.archive || defaults.archive,
|
|
102
105
|
activeOnly: options.activeOnly || options['active-only'] || defaults.activeOnly,
|
|
103
|
-
includeFailed: options.includeFailed || options['include-failed'] || defaults.includeFailed,
|
|
104
106
|
maxConcurrentJobs: options.maxConcurrentJobs || defaults.maxConcurrentJobs,
|
|
105
107
|
maxMemoryPercent: options.maxMemoryPercent || defaults.maxMemoryPercent,
|
|
106
108
|
|
|
@@ -104,7 +104,7 @@ export class QueueManager {
|
|
|
104
104
|
.filter(({ qname, qrl }) => {
|
|
105
105
|
const isFifo = qname.endsWith('.fifo')
|
|
106
106
|
const isDead = isFifo ? qname.endsWith('_dead.fifo') : qname.endsWith('_dead')
|
|
107
|
-
return !isDead
|
|
107
|
+
return this.opt.includeDead ? true : !isDead
|
|
108
108
|
})
|
|
109
109
|
// then icehouse
|
|
110
110
|
.filter(({ qname, qrl }) => !this.keepInIcehouse(qrl, now))
|
|
@@ -149,6 +149,7 @@ export class QueueManager {
|
|
|
149
149
|
|
|
150
150
|
getPairs () {
|
|
151
151
|
const now = new Date()
|
|
152
|
+
this.selectedPairs.sort(() => 0.5 - Math.random())
|
|
152
153
|
return this.selectedPairs.filter(({ qname, qrl }) => !this.keepInIcehouse(qrl, now))
|
|
153
154
|
}
|
|
154
155
|
|