Skip to content

Commit

Permalink
perf(scripts): remove token after moving to wait or delayed (#2731)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed May 10, 2024
1 parent 6d84156 commit 7ee8f74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Expand Up @@ -5,6 +5,7 @@
KEYS[1] active key
KEYS[2] delayed key
KEYS[3] job key
KEYS[4] stalled key
ARGV[1] delayedTimestamp
ARGV[2] the id of the job
Expand All @@ -21,14 +22,13 @@
local rcall = redis.call

if rcall("EXISTS", KEYS[3]) == 1 then
local lockKey
local lock

-- Check for job lock
if ARGV[3] ~= "0" then
lockKey = KEYS[3] .. ':lock'
lock = rcall("GET", lockKey)
if lock ~= ARGV[3] then
local lockKey = KEYS[3] .. ':lock'
if rcall("GET", lockKey) == ARGV[3] then
rcall("DEL", lockKey)
rcall("SREM", KEYS[4], ARGV[2])
else
return -2
end
end
Expand All @@ -38,10 +38,6 @@ if rcall("EXISTS", KEYS[3]) == 1 then
rcall("PUBLISH", KEYS[2], (score / 0x1000))
rcall("LREM", KEYS[1], 0, ARGV[2])

if lock then
rcall("DEL", lockKey)
end

return 0
else
return -1
Expand Down
7 changes: 5 additions & 2 deletions lib/commands/retryJob-5.lua → lib/commands/retryJob-6.lua
Expand Up @@ -7,6 +7,7 @@
KEYS[3] jobId
KEYS[4] 'meta-paused'
KEYS[5] 'paused'
KEYS[6] stalled key
ARGV[1] pushCmd
ARGV[2] jobId
Expand All @@ -26,8 +27,10 @@ if rcall("EXISTS", KEYS[3]) == 1 then
-- Check for job lock
if ARGV[3] ~= "0" then
local lockKey = KEYS[3] .. ':lock'
local lock = rcall("GET", lockKey)
if lock ~= ARGV[3] then
if rcall("GET", lockKey) == ARGV[3] then
rcall("DEL", lockKey)
rcall("SREM", KEYS[6], ARGV[2])
else
return -2
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/scripts.js
Expand Up @@ -307,7 +307,7 @@ const scripts = {
timestamp = timestamp * 0x1000 + (jobId & 0xfff);
}

const keys = _.map(['active', 'delayed', jobId], name => {
const keys = _.map(['active', 'delayed', jobId, 'stalled'], name => {
return queue.toKey(name);
});
return keys.concat([
Expand Down Expand Up @@ -478,7 +478,7 @@ const scripts = {
const jobId = job.id;

const keys = _.map(
['active', 'wait', jobId, 'meta-paused', 'paused'],
['active', 'wait', jobId, 'meta-paused', 'paused', 'stalled'],
name => {
return queue.toKey(name);
}
Expand Down

0 comments on commit 7ee8f74

Please sign in to comment.