Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(retry-job): throw error when job is not in active state #2741

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/commands/moveToFinished-9.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
0 OK
-1 Missing key.
-2 Missing lock.
-3 - Job not in active set.

Events:
'completed/failed'
Expand Down Expand Up @@ -81,15 +82,13 @@ local function collectMetrics(metaKey, dataPointsList, maxDataPoints, timestamp)
end
end

-- Includes
--- @include "includes/removeLock"

if rcall("EXISTS", KEYS[3]) == 1 then -- // Make sure job exists
if ARGV[5] ~= "0" then
local lockKey = KEYS[3] .. ':lock'
if rcall("GET", lockKey) == ARGV[5] then
rcall("DEL", lockKey)
rcall("SREM", KEYS[8], ARGV[1])
else
return -2
end
local errorCode = removeLock(KEYS[3], KEYS[8], ARGV[5], ARGV[1])
if errorCode < 0 then
return errorCode
end

-- Remove from active list (if not active we shall return error)
Expand Down
18 changes: 7 additions & 11 deletions lib/commands/retryJob-7.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,23 @@
0 - OK
-1 - Missing key
-2 - Job Not locked
-3 - Job not in active set
]]
local rcall = redis.call

-- Includes
--- @include "includes/addJobWithPriority"
--- @include "includes/getTargetQueueList"
--- @include "includes/removeLock"

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

-- Check for job lock
if ARGV[3] ~= "0" then
local lockKey = KEYS[3] .. ':lock'
if rcall("GET", lockKey) == ARGV[3] then
rcall("DEL", lockKey)
rcall("SREM", KEYS[6], ARGV[2])
else
return -2
end
local errorCode = removeLock(KEYS[3], KEYS[6], ARGV[3], ARGV[2])
if errorCode < 0 then
return errorCode
end

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

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

Expand Down
3 changes: 3 additions & 0 deletions test/test_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ describe('Job', () => {
.then(isFailed => {
expect(isFailed).to.be(false);
})
.then(() => {
return scripts.moveToActive(queue);
})
.then(() => {
return job.moveToFailed(new Error('test error'), true);
})
Expand Down
Loading