Skip to content

Commit

Permalink
refactor(finished): reuse removeLock include (#2537)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Apr 23, 2024
1 parent d6066f4 commit b91dd72
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/commands/moveToFinished-14.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ local rcall = redis.call
--- @include "includes/removeJobKeys"
--- @include "includes/removeJobsByMaxAge"
--- @include "includes/removeJobsByMaxCount"
--- @include "includes/removeLock"
--- @include "includes/removeParentDependencyKey"
--- @include "includes/trimEvents"
--- @include "includes/updateParentDepsIfNeeded"
Expand All @@ -77,28 +78,17 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
local opts = cmsgpack.unpack(ARGV[8])

local token = opts['token']

local errorCode = removeLock(jobIdKey, KEYS[5], token, ARGV[1])
if errorCode < 0 then
return errorCode
end

local attempts = opts['attempts']
local maxMetricsSize = opts['maxMetricsSize']
local maxCount = opts['keepJobs']['count']
local maxAge = opts['keepJobs']['age']

if token ~= "0" then
local lockKey = jobIdKey .. ':lock'
local lockToken = rcall("GET", lockKey)
if lockToken == token then
rcall("DEL", lockKey)
rcall("SREM", KEYS[5], ARGV[1])
else
if lockToken then
-- Lock exists but token does not match
return -6
else
-- Lock is missing completely
return -2
end
end
end

if rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then -- // Make sure it does not have pending dependencies
return -4
end
Expand Down

0 comments on commit b91dd72

Please sign in to comment.