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: queues stop working when there are more than 8k jobs with the same timestamp #550

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/lua/raiseDelayedJobs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ returns number of jobs raised and the timestamp of the next job (within the near
local now = tonumber(ARGV[1])

-- raise any delayed jobs that are now valid by moving from delayed to waiting
local raising = redis.call("zrangebyscore", KEYS[1], 0, ARGV[1])
local numRaising = #raising
local offset = 0
-- There is a default 1024 element restriction
local count = 1000
while true do
local raising = redis.call("zrangebyscore", KEYS[1], 0, ARGV[1], 'LIMIT', offset, count)
local numRaising = #raising
offset = offset + numRaising

if numRaising > 0 then
redis.call("lpush", KEYS[2], unpack(raising))
redis.call("zremrangebyscore", KEYS[1], 0, ARGV[1])
if numRaising > 0 then
redis.call("lpush", KEYS[2], unpack(raising))
else
break
end
end
redis.call("zremrangebyscore", KEYS[1], 0, ARGV[1])

local head = redis.call("zrange", KEYS[1], 0, 0, "WITHSCORES")
local nearTerm = -1
Expand All @@ -25,4 +33,4 @@ if next(head) ~= nil then
nearTerm = proximal[2]
end

return {numRaising, nearTerm}
return {offset, nearTerm}