Skip to content

Commit

Permalink
fixes #58
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwitt committed Jan 19, 2024
1 parent 0bf94e4 commit 40178cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qdone",
"version": "2.0.17-alpha",
"version": "2.0.18-alpha",
"description": "Language agnostic job queue for SQS",
"type": "module",
"main": "./index.js",
Expand Down
27 changes: 18 additions & 9 deletions src/idleQueues.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,24 @@ const metricNames = [
* Actual SQS call, used in conjunction with cache.
*/
export async function _cheapIdleCheck (qname, qrl, opt) {
const client = getSQSClient()
const cmd = new GetQueueAttributesCommand({ AttributeNames: attributeNames, QueueUrl: qrl })
const data = await client.send(cmd)
debug('data', data)
const result = data.Attributes
result.queue = qname.slice(opt.prefix.length)
// We are idle if all the messages attributes are zero
result.idle = attributeNames.filter(k => result[k] === '0').length === attributeNames.length
return { result, SQS: 1 }
try {
const client = getSQSClient()
const cmd = new GetQueueAttributesCommand({ AttributeNames: attributeNames, QueueUrl: qrl })
const data = await client.send(cmd)
debug('data', data)
const result = data.Attributes
result.queue = qname.slice(opt.prefix.length)
// We are idle if all the messages attributes are zero
result.idle = attributeNames.filter(k => result[k] === '0').length === attributeNames.length
return { result, SQS: 1 }
} catch (e) {
if (e instanceof QueueDoesNotExist) {
// Count deleted queues as idle
return { idle: true, SQS: 1 }
} else {
throw e
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/jobExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class JobExecutor {
// Execute job
try {
const queue = qname.slice(this.opt.prefix.length)
const result = await withSentry(() => callback(queue, payload), this.opt, { job })
const result = await callback(queue, payload)
debug('executeJob callback finished', { payload, result })
if (this.opt.verbose) {
console.error(chalk.green('SUCCESS'), message.Body)
Expand Down

0 comments on commit 40178cd

Please sign in to comment.