-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(change-delay): add delay marker when needed (#2411)
- Loading branch information
1 parent
b3ab285
commit 8b62d28
Showing
7 changed files
with
79 additions
and
63 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 was deleted.
Oops, something went wrong.
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,57 @@ | ||
--[[ | ||
Change job delay when it is in delayed set. | ||
Input: | ||
KEYS[1] delayed key | ||
KEYS[2] meta key | ||
KEYS[3] marker key | ||
KEYS[4] events stream | ||
ARGV[1] delay | ||
ARGV[2] delayedTimestamp | ||
ARGV[3] the id of the job | ||
ARGV[4] job key | ||
Output: | ||
0 - OK | ||
-1 - Missing job. | ||
-3 - Job not in delayed set. | ||
Events: | ||
- delayed key. | ||
]] | ||
local rcall = redis.call | ||
|
||
-- Includes | ||
--- @include "includes/addDelayMarkerIfNeeded" | ||
--- @include "includes/getOrSetMaxEvents" | ||
--- @include "includes/isQueuePaused" | ||
|
||
if rcall("EXISTS", ARGV[4]) == 1 then | ||
local jobId = ARGV[3] | ||
local score = tonumber(ARGV[2]) | ||
local delayedTimestamp = (score / 0x1000) | ||
|
||
local numRemovedElements = rcall("ZREM", KEYS[1], jobId) | ||
|
||
if numRemovedElements < 1 then | ||
return -3 | ||
end | ||
|
||
rcall("HSET", ARGV[4], "delay", tonumber(ARGV[1])) | ||
rcall("ZADD", KEYS[1], score, jobId) | ||
|
||
local maxEvents = getOrSetMaxEvents(KEYS[2]) | ||
|
||
rcall("XADD", KEYS[4], "MAXLEN", "~", maxEvents, "*", "event", "delayed", | ||
"jobId", jobId, "delay", delayedTimestamp) | ||
|
||
-- mark that a delayed job is available | ||
local isPaused = isQueuePaused(KEYS[2]) | ||
if not isPaused then | ||
addDelayMarkerIfNeeded(KEYS[3], KEYS[1]) | ||
end | ||
|
||
return 0 | ||
else | ||
return -1 | ||
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