-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(job): validate job existence when adding a log (#2562)
- Loading branch information
1 parent
cce0774
commit f87e3fe
Showing
4 changed files
with
71 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--[[ | ||
Add job log | ||
Input: | ||
KEYS[1] job id key | ||
KEYS[2] job logs key | ||
ARGV[1] id | ||
ARGV[2] log | ||
ARGV[3] keepLogs | ||
Output: | ||
-1 - Missing job. | ||
]] | ||
local rcall = redis.call | ||
|
||
if rcall("EXISTS", KEYS[1]) == 1 then -- // Make sure job exists | ||
local logCount = rcall("RPUSH", KEYS[2], ARGV[2]) | ||
|
||
if ARGV[3] ~= '' then | ||
local keepLogs = tonumber(ARGV[3]) | ||
rcall("LTRIM", KEYS[2], -keepLogs, -1) | ||
|
||
return math.min(keepLogs, logCount) | ||
end | ||
|
||
return logCount | ||
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