Skip to content

Commit b91dd72

Browse files
authored
refactor(finished): reuse removeLock include (#2537)
1 parent d6066f4 commit b91dd72

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/commands/moveToFinished-14.lua

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ local rcall = redis.call
6868
--- @include "includes/removeJobKeys"
6969
--- @include "includes/removeJobsByMaxAge"
7070
--- @include "includes/removeJobsByMaxCount"
71+
--- @include "includes/removeLock"
7172
--- @include "includes/removeParentDependencyKey"
7273
--- @include "includes/trimEvents"
7374
--- @include "includes/updateParentDepsIfNeeded"
@@ -77,28 +78,17 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
7778
local opts = cmsgpack.unpack(ARGV[8])
7879

7980
local token = opts['token']
81+
82+
local errorCode = removeLock(jobIdKey, KEYS[5], token, ARGV[1])
83+
if errorCode < 0 then
84+
return errorCode
85+
end
86+
8087
local attempts = opts['attempts']
8188
local maxMetricsSize = opts['maxMetricsSize']
8289
local maxCount = opts['keepJobs']['count']
8390
local maxAge = opts['keepJobs']['age']
8491

85-
if token ~= "0" then
86-
local lockKey = jobIdKey .. ':lock'
87-
local lockToken = rcall("GET", lockKey)
88-
if lockToken == token then
89-
rcall("DEL", lockKey)
90-
rcall("SREM", KEYS[5], ARGV[1])
91-
else
92-
if lockToken then
93-
-- Lock exists but token does not match
94-
return -6
95-
else
96-
-- Lock is missing completely
97-
return -2
98-
end
99-
end
100-
end
101-
10292
if rcall("SCARD", jobIdKey .. ":dependencies") ~= 0 then -- // Make sure it does not have pending dependencies
10393
return -4
10494
end

0 commit comments

Comments
 (0)