From 7ee8f7430a68492c9ce768e7108443592f49d74c Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Fri, 10 May 2024 07:51:07 -0600 Subject: [PATCH] perf(scripts): remove token after moving to wait or delayed (#2731) --- .../{moveToDelayed-3.lua => moveToDelayed-4.lua} | 16 ++++++---------- lib/commands/{retryJob-5.lua => retryJob-6.lua} | 7 +++++-- lib/scripts.js | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) rename lib/commands/{moveToDelayed-3.lua => moveToDelayed-4.lua} (77%) rename lib/commands/{retryJob-5.lua => retryJob-6.lua} (84%) diff --git a/lib/commands/moveToDelayed-3.lua b/lib/commands/moveToDelayed-4.lua similarity index 77% rename from lib/commands/moveToDelayed-3.lua rename to lib/commands/moveToDelayed-4.lua index 77825fa6b..bc8e09b51 100644 --- a/lib/commands/moveToDelayed-3.lua +++ b/lib/commands/moveToDelayed-4.lua @@ -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 @@ -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 @@ -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 diff --git a/lib/commands/retryJob-5.lua b/lib/commands/retryJob-6.lua similarity index 84% rename from lib/commands/retryJob-5.lua rename to lib/commands/retryJob-6.lua index 736862e53..463ac22c3 100644 --- a/lib/commands/retryJob-5.lua +++ b/lib/commands/retryJob-6.lua @@ -7,6 +7,7 @@ KEYS[3] jobId KEYS[4] 'meta-paused' KEYS[5] 'paused' + KEYS[6] stalled key ARGV[1] pushCmd ARGV[2] jobId @@ -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 diff --git a/lib/scripts.js b/lib/scripts.js index 59ebcaa53..267d9c416 100644 --- a/lib/scripts.js +++ b/lib/scripts.js @@ -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([ @@ -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); }