Skip to content
Merged
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
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}