Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(priority): consider paused state when calling getCountsPerPriority #2748

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading