qdone 2.0.16-alpha → 2.0.18-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 +5 -3
- package/commonjs/src/idleQueues.js +21 -9
- package/commonjs/src/scheduler/jobExecutor.js +3 -3
- package/npm-shrinkwrap.json +16001 -0
- package/package.json +1 -1
- package/src/consumer.js +4 -2
- package/src/idleQueues.js +18 -9
- package/src/scheduler/jobExecutor.js +1 -1
package/package.json
CHANGED
package/src/consumer.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Consumer implementation.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { freemem, totalmem } from 'os'
|
|
5
6
|
import { ReceiveMessageCommand, QueueDoesNotExist } from '@aws-sdk/client-sqs'
|
|
6
7
|
import chalk from 'chalk'
|
|
7
8
|
import Debug from 'debug'
|
|
@@ -117,9 +118,10 @@ export async function processMessages (queues, callback, options) {
|
|
|
117
118
|
const maxLatency = 100
|
|
118
119
|
const latency = systemMonitor.getLatency() || 10
|
|
119
120
|
const latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
|
|
120
|
-
const
|
|
121
|
+
const freememFactor = Math.min(1, Math.max(0, freemem() - totalmem() / 2) / totalmem())
|
|
122
|
+
const targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor)
|
|
121
123
|
let jobsLeft = targetJobs
|
|
122
|
-
debug({ jobCount: jobExecutor.activeJobCount(), maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, targetJobs, activeQrls })
|
|
124
|
+
debug({ jobCount: jobExecutor.activeJobCount(), maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
|
|
123
125
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
124
126
|
debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
125
127
|
if (jobsLeft <= 0 || activeQrls.has(qrl)) continue
|
package/src/idleQueues.js
CHANGED
|
@@ -37,15 +37,24 @@ const metricNames = [
|
|
|
37
37
|
* Actual SQS call, used in conjunction with cache.
|
|
38
38
|
*/
|
|
39
39
|
export async function _cheapIdleCheck (qname, qrl, opt) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
try {
|
|
41
|
+
const client = getSQSClient()
|
|
42
|
+
const cmd = new GetQueueAttributesCommand({ AttributeNames: attributeNames, QueueUrl: qrl })
|
|
43
|
+
const data = await client.send(cmd)
|
|
44
|
+
debug('data', data)
|
|
45
|
+
const result = data.Attributes
|
|
46
|
+
result.queue = qname.slice(opt.prefix.length)
|
|
47
|
+
// We are idle if all the messages attributes are zero
|
|
48
|
+
result.idle = attributeNames.filter(k => result[k] === '0').length === attributeNames.length
|
|
49
|
+
return { result, SQS: 1 }
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e instanceof QueueDoesNotExist) {
|
|
52
|
+
// Count deleted queues as idle
|
|
53
|
+
return { idle: true, SQS: 1 }
|
|
54
|
+
} else {
|
|
55
|
+
throw e
|
|
56
|
+
}
|
|
57
|
+
}
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
/**
|
|
@@ -242,7 +242,7 @@ export class JobExecutor {
|
|
|
242
242
|
// Execute job
|
|
243
243
|
try {
|
|
244
244
|
const queue = qname.slice(this.opt.prefix.length)
|
|
245
|
-
const result = await
|
|
245
|
+
const result = await callback(queue, payload)
|
|
246
246
|
debug('executeJob callback finished', { payload, result })
|
|
247
247
|
if (this.opt.verbose) {
|
|
248
248
|
console.error(chalk.green('SUCCESS'), message.Body)
|