Skip to content

Commit

Permalink
fix for #35, make idle queue pairing work properly for FIFO
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwitt committed Jul 6, 2018
1 parent 93df968 commit 758849b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/idleQueues.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ function processQueue (qname, qrl, options) {
* Processes a queue and its fail queue, treating them as a unit.
*/
function processQueuePair (qname, qrl, options) {
const fqname = qname + options['fail-suffix']
const fqrl = qrl + options['fail-suffix']
const isFifo = qname.endsWith('.fifo')
const normalizeOptions = Object.assign({}, options, {fifo: isFifo})
const fqname = qrlCache.normalizeFailQueueName(qname, normalizeOptions)
const fqrl = qrlCache.normalizeFailQueueName(qrl, normalizeOptions)
return checkIdle(qname, qrl, options).then(result => {
debug('result', result)
if (result.idle) {
Expand Down Expand Up @@ -258,7 +260,10 @@ exports.idleQueues = function idleQueues (queues, options) {
entries = entries
.filter(function (entry) {
const suf = options['fail-suffix']
return options['include-failed'] ? true : entry.qname.slice(-suf.length) !== suf
const sufFifo = options['fail-suffix'] + qrlCache.fifoSuffix
const isFail = entry.qname.endsWith(suf)
const isFifoFail = entry.qname.endsWith(sufFifo)
return options['include-failed'] ? true : (!isFail && !isFifoFail)
})

// But only if we have queues to remove
Expand Down
1 change: 1 addition & 0 deletions src/qrlCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function _get (qname) {
// Normalizes a queue name to end with .fifo if options.fifo is set
//
const fifoSuffix = '.fifo'
exports.fifoSuffix = fifoSuffix
exports.normalizeQueueName = function normalizeQueueName (qname, options) {
const sliced = qname.slice(0, -fifoSuffix.length)
const suffix = qname.slice(-fifoSuffix.length)
Expand Down
48 changes: 48 additions & 0 deletions test/test.cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,54 @@ describe('cli', function () {
}))
})

describe('qdone idle-queues test.fifo # (primary queue is idle and a FIFO, failed queue is active)', function () {
before(function () {
AWS.mock('SQS', 'getQueueUrl', function (params, callback) {
callback(null, {QueueUrl: `https://q.amazonaws.com/123456789101/${params.QueueName}`})
})
AWS.mock('SQS', 'listQueues', function (params, callback) {
callback(null, {QueueUrls: [
`https://q.amazonaws.com/123456789101/${params.QueueNamePrefix}`,
`https://q.amazonaws.com/123456789101/${params.QueueNamePrefix}_failed.fifo`
]})
})
AWS.mock('SQS', 'getQueueAttributes', function (params, callback) {
callback(null, {
Attributes: {
ApproximateNumberOfMessages: '0',
ApproximateNumberOfMessagesDelayed: '0',
ApproximateNumberOfMessagesNotVisible: '0'
}
})
})
AWS.mock('CloudWatch', 'getMetricStatistics', function (params, callback) {
// Always return data for failed queue
if (params.Dimensions[0].Value === 'qdone_test_failed.fifo') {
callback(null, {
Label: params.MetricName,
Datapoints: [
{Timestamp: new Date(), Sum: 0, Metric: 'Count'},
{Timestamp: new Date(), Sum: 1, Metric: 'Count'}
]
})
} else {
callback(null, {
Label: params.MetricName,
Datapoints: [
{Timestamp: new Date(), Sum: 0, Metric: 'Count'},
{Timestamp: new Date(), Sum: 0, Metric: 'Count'}
]
})
}
})
})
it('should print queue name to stdout and exit 0',
cliTest(['idle-queues', 'test.fifo'], function (result, stdout, stderr) {
expect(stderr).to.contain('Queue test.fifo has been idle for the last 60 minutes.')
expect(stderr).to.contain('Queue test_failed.fifo has been active in the last 60 minutes.')
}))
})

describe('qdone idle-queues \'test*\' --unpair --include-failed # (inactive queue)', function () {
before(function () {
AWS.mock('SQS', 'getQueueUrl', function (params, callback) {
Expand Down

0 comments on commit 758849b

Please sign in to comment.