Skip to content

Commit c29e3b0

Browse files
authored
fix(retry-job): throw error when job is not in active state (#2741)
1 parent b3fb4a2 commit c29e3b0

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

lib/commands/moveToFinished-9.lua

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
0 OK
3636
-1 Missing key.
3737
-2 Missing lock.
38+
-3 - Job not in active set.
3839
3940
Events:
4041
'completed/failed'
@@ -81,15 +82,13 @@ local function collectMetrics(metaKey, dataPointsList, maxDataPoints, timestamp)
8182
end
8283
end
8384

85+
-- Includes
86+
--- @include "includes/removeLock"
87+
8488
if rcall("EXISTS", KEYS[3]) == 1 then -- // Make sure job exists
85-
if ARGV[5] ~= "0" then
86-
local lockKey = KEYS[3] .. ':lock'
87-
if rcall("GET", lockKey) == ARGV[5] then
88-
rcall("DEL", lockKey)
89-
rcall("SREM", KEYS[8], ARGV[1])
90-
else
91-
return -2
92-
end
89+
local errorCode = removeLock(KEYS[3], KEYS[8], ARGV[5], ARGV[1])
90+
if errorCode < 0 then
91+
return errorCode
9392
end
9493

9594
-- Remove from active list (if not active we shall return error)

lib/commands/retryJob-7.lua

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,23 @@
2121
0 - OK
2222
-1 - Missing key
2323
-2 - Job Not locked
24+
-3 - Job not in active set
2425
]]
2526
local rcall = redis.call
2627

2728
-- Includes
2829
--- @include "includes/addJobWithPriority"
2930
--- @include "includes/getTargetQueueList"
31+
--- @include "includes/removeLock"
3032

3133
if rcall("EXISTS", KEYS[3]) == 1 then
32-
33-
-- Check for job lock
34-
if ARGV[3] ~= "0" then
35-
local lockKey = KEYS[3] .. ':lock'
36-
if rcall("GET", lockKey) == ARGV[3] then
37-
rcall("DEL", lockKey)
38-
rcall("SREM", KEYS[6], ARGV[2])
39-
else
40-
return -2
41-
end
34+
local errorCode = removeLock(KEYS[3], KEYS[6], ARGV[3], ARGV[2])
35+
if errorCode < 0 then
36+
return errorCode
4237
end
4338

44-
rcall("LREM", KEYS[1], 0, ARGV[2])
39+
local numRemovedElements = rcall("LREM", KEYS[1], -1, ARGV[2])
40+
if numRemovedElements < 1 then return -3 end
4541

4642
local target = getTargetQueueList(KEYS[4], KEYS[2], KEYS[5])
4743

test/test_job.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ describe('Job', () => {
663663
.then(isFailed => {
664664
expect(isFailed).to.be(false);
665665
})
666+
.then(() => {
667+
return scripts.moveToActive(queue);
668+
})
666669
.then(() => {
667670
return job.moveToFailed(new Error('test error'), true);
668671
})

0 commit comments

Comments
 (0)