qdone 2.0.15-alpha → 2.0.17-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/scheduler/jobExecutor.js +4 -4
- package/commonjs/src/sentry.js +111 -0
- package/npm-shrinkwrap.json +16001 -0
- package/package.json +1 -1
- package/src/consumer.js +4 -2
- package/src/scheduler/jobExecutor.js +4 -6
- package/src/sentry.js +17 -4
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
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
* their visibility timeouts and deleting them when they are successful.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
DeleteMessageBatchCommand
|
|
9
|
-
} from '@aws-sdk/client-sqs'
|
|
6
|
+
import { ChangeMessageVisibilityBatchCommand, DeleteMessageBatchCommand } from '@aws-sdk/client-sqs'
|
|
7
|
+
|
|
10
8
|
import chalk from 'chalk'
|
|
11
9
|
import Debug from 'debug'
|
|
12
10
|
|
|
11
|
+
import { withSentry } from '../sentry.js'
|
|
13
12
|
import { getSQSClient } from '../sqs.js'
|
|
14
13
|
|
|
15
14
|
const debug = Debug('qdone:jobExecutor')
|
|
@@ -243,7 +242,7 @@ export class JobExecutor {
|
|
|
243
242
|
// Execute job
|
|
244
243
|
try {
|
|
245
244
|
const queue = qname.slice(this.opt.prefix.length)
|
|
246
|
-
const result = await callback(queue, payload)
|
|
245
|
+
const result = await withSentry(() => callback(queue, payload), this.opt, { job })
|
|
247
246
|
debug('executeJob callback finished', { payload, result })
|
|
248
247
|
if (this.opt.verbose) {
|
|
249
248
|
console.error(chalk.green('SUCCESS'), message.Body)
|
|
@@ -263,7 +262,6 @@ export class JobExecutor {
|
|
|
263
262
|
}
|
|
264
263
|
this.stats.jobsSucceeded++
|
|
265
264
|
} catch (err) {
|
|
266
|
-
// debug('exec.catch', err)
|
|
267
265
|
// Fail path for job execution
|
|
268
266
|
if (this.opt.verbose) {
|
|
269
267
|
console.error(chalk.red('FAILED'), message.Body)
|
package/src/sentry.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import Debug from 'debug'
|
|
6
|
-
import { init, captureException } from '@sentry/node'
|
|
6
|
+
import { init, withScope, captureException } from '@sentry/node'
|
|
7
7
|
|
|
8
8
|
const debug = Debug('qdone:sentry')
|
|
9
9
|
|
|
10
10
|
let sentryWasInit = false
|
|
11
|
-
export async function withSentry (callback, opt) {
|
|
11
|
+
export async function withSentry (callback, opt, contexts) {
|
|
12
|
+
debug({ withSentry: { callback, opt, contexts } })
|
|
12
13
|
// Bail if sentry isn't enabled
|
|
13
14
|
if (!opt.sentryDsn) return callback()
|
|
14
15
|
|
|
@@ -23,8 +24,20 @@ export async function withSentry (callback, opt) {
|
|
|
23
24
|
return result
|
|
24
25
|
} catch (err) {
|
|
25
26
|
debug({ err })
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
await withScope(async function (scope) {
|
|
28
|
+
scope.setContext('opt', opt)
|
|
29
|
+
if (contexts instanceof Object) {
|
|
30
|
+
for (const key in contexts) scope.setContext(key, contexts[key])
|
|
31
|
+
if (err.stdout && err.stderr) {
|
|
32
|
+
const { stdout, stderr } = err
|
|
33
|
+
scope.setContext('IO', { stdout, stderr })
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const sentryResult = await captureException(err)
|
|
37
|
+
debug({ sentryResult })
|
|
38
|
+
})
|
|
28
39
|
throw err
|
|
29
40
|
}
|
|
30
41
|
}
|
|
42
|
+
|
|
43
|
+
debug('loaded')
|