local rcall = redis.call;
local jobKey = KEYS[1]
if rcall("EXISTS", jobKey) == 1 then
local jobId = ARGV[1]
if (rcall("ZREM", KEYS[3], jobId) == 1) then
local attributesToRemove = {}
if ARGV[5] == "1" then
table.insert(attributesToRemove, "atm")
end
if ARGV[6] == "1" then
table.insert(attributesToRemove, "ats")
end
rcall("HDEL", jobKey, "finishedOn", "processedOn", ARGV[3], unpack(attributesToRemove))
local target, isPausedOrMaxed = getTargetQueueList(KEYS[5], KEYS[7], KEYS[4], KEYS[6])
addJobInTargetList(target, KEYS[8], ARGV[2], isPausedOrMaxed, jobId)
local parentKey = rcall("HGET", jobKey, "parentKey")
if parentKey and rcall("EXISTS", parentKey) == 1 then
if ARGV[4] == "failed" then
if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
rcall("ZREM", parentKey .. ":failed", jobKey) == 1 then
rcall("SADD", parentKey .. ":dependencies", jobKey)
end
else
if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
rcall("SADD", parentKey .. ":dependencies", jobKey)
end
end
end
local maxEvents = getOrSetMaxEvents(KEYS[5])
rcall("XADD", KEYS[2], "MAXLEN", "~", maxEvents, "*", "event", "waiting",
"jobId", jobId, "prev", ARGV[4]);
return 1
else
return -3
end
else
return -1
end