Skip to content

Commit

Permalink
fix(priority): consider paused state when calling getCountsPerPriority (
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Jun 21, 2024
1 parent 79113ac commit 6c2719a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 26 deletions.
25 changes: 0 additions & 25 deletions lib/commands/getCountsPerPriority-2.lua

This file was deleted.

37 changes: 37 additions & 0 deletions lib/commands/getCountsPerPriority-4.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--[[
Get counts per provided states
Input:
KEYS[1] wait key
KEYS[2] paused key
KEYS[3] meta-paused key
KEYS[4] priority key
ARGV[1...] priorities
]]
local rcall = redis.call
local results = {}
local prioritizedKey = KEYS[4]

-- Includes
--- @include "includes/getTargetQueueList"

for i = 1, #ARGV do
local priority = tonumber(ARGV[i])
if priority == 0 then
local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
local count = rcall("LLEN", target) - rcall("ZCARD", prioritizedKey)
if count < 0 then
-- considering when last waiting job is moved to active before
-- removing priority reference
results[#results+1] = 0
else
results[#results+1] = count
end
else
results[#results+1] = rcall("ZCOUNT", prioritizedKey,
priority, priority)
end
end

return results
7 changes: 6 additions & 1 deletion lib/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ const scripts = {
},

getCountsPerPriorityArgs(queue, priorities) {
const keys = [queue.keys.wait, queue.keys.priority];
const keys = [
queue.keys.wait,
queue.keys.paused,
queue.keys['meta-paused'],
queue.keys.priority
];

const args = priorities;

Expand Down
22 changes: 22 additions & 0 deletions test/test_getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,28 @@ describe('Jobs getters', function() {
});
});
});

describe('when queue is paused', () => {
it('returns job counts per priority', async () => {
await queue.pause();
const jobsArray = Array.from(Array(42).keys()).map(index => ({
name: 'test',
data: {},
opts: {
priority: index % 4
}
}));
await queue.addBulk(jobsArray);
const counts = await queue.getCountsPerPriority([0, 1, 2, 3]);

expect(counts).to.be.eql({
'0': 11,
'1': 11,
'2': 10,
'3': 10
});
});
});
});

it('fails jobs that exceed their specified timeout', done => {
Expand Down

0 comments on commit 6c2719a

Please sign in to comment.