-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(delayed): avoid using jobId in order to schedule delayed jobs (#2587
- Loading branch information
1 parent
aecac66
commit 228db2c
Showing
13 changed files
with
69 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--[[ | ||
Bake in the job id first 12 bits into the timestamp | ||
to guarantee correct execution order of delayed jobs | ||
(up to 4096 jobs per given timestamp or 4096 jobs apart per timestamp) | ||
WARNING: Jobs that are so far apart that they wrap around will cause FIFO to fail | ||
]] | ||
local function getDelayedScore(delayedKey, timestamp, delay) | ||
local delayedTimestamp = (delay > 0 and (tonumber(timestamp) + delay)) or tonumber(timestamp) | ||
local minScore = delayedTimestamp * 0x1000 | ||
local maxScore = (delayedTimestamp + 1 ) * 0x1000 - 1 | ||
|
||
local result = rcall("ZREVRANGEBYSCORE", delayedKey, maxScore, | ||
minScore, "WITHSCORES","LIMIT", 0, 1) | ||
if #result then | ||
local currentMaxScore = tonumber(result[2]) | ||
if currentMaxScore ~= nil then | ||
if currentMaxScore >= maxScore then | ||
return maxScore, delayedTimestamp | ||
else | ||
return currentMaxScore + 1, delayedTimestamp | ||
end | ||
end | ||
end | ||
return minScore, delayedTimestamp | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters