Skip to content

Commit

Permalink
fix: Include prioritized jobs in queue depth metric (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic authored Jun 6, 2024
1 parent 55b5c48 commit cdc26c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/bull/test/bull-metrics-collector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ describe('BullMetricsCollector', () => {
queue = new Queue('foo')

await queue.add('test-job')
await queue.add('prioritized-job', {}, { priority: 1 })

const metrics = await collector.collect()

expect(metrics.length).toEqual(2)

expect(metrics[0].identifier).toEqual('qd')
expect(metrics[0].queueName).toEqual('foo')
expect(metrics[0].value).toEqual(1)
expect(metrics[0].value).toEqual(2)
expect(metrics[1].identifier).toEqual('busy')
expect(metrics[1].queueName).toEqual('foo')
expect(metrics[1].value).toEqual(0)
Expand Down
4 changes: 2 additions & 2 deletions packages/bullmq/src/bull-mq-metrics-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class BullMQMetricsCollector extends WorkerMetricsCollector {

for (const queueName of this.queueNames) {
const queue = new Queue(queueName, { connection: this.redis })
const jobCounts = await queue.getJobCounts('waiting', 'active')
const jobCounts = await queue.getJobCounts('waiting', 'active', 'prioritized')

metrics.push(new Metric('qd', new Date(), jobCounts.waiting, queueName))
metrics.push(new Metric('qd', new Date(), jobCounts.waiting + jobCounts.prioritized, queueName))
metrics.push(new Metric('busy', new Date(), jobCounts.active, queueName))
}

Expand Down
3 changes: 2 additions & 1 deletion packages/bullmq/test/bull-mq-metrics-collector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ describe('BullMQMetricsCollector', () => {

const queue = new Queue('foo', { connection: collector.redis })
await queue.add('test-job')
await queue.add('prioritized-job', {}, { priority: 1 })

const metrics = await collector.collect()

expect(metrics.length).toEqual(2)

expect(metrics[0].identifier).toEqual('qd')
expect(metrics[0].queueName).toEqual('foo')
expect(metrics[0].value).toEqual(1)
expect(metrics[0].value).toEqual(2)
expect(metrics[1].identifier).toEqual('busy')
expect(metrics[1].queueName).toEqual('foo')
expect(metrics[1].value).toEqual(0)
Expand Down

0 comments on commit cdc26c5

Please sign in to comment.