local active_key = KEYS[1]
local delayed_key = KEYS[2]
local failed_key = KEYS[3]
local job_id = ARGV[1]
local error_msg = ARGV[2]
local now = ARGV[3]
local retry_at = ARGV[4]
local is_final = tonumber(ARGV[5])
redis.call('srem', active_key, job_id)
local job_key = "rbq:job:" .. job_id
if is_final == 1 then
redis.call('lpush', failed_key, job_id)
redis.call('hmset', job_key,
'state', '"Failed"',
'failed_at', now,
'last_error', error_msg
)
else
redis.call('zadd', delayed_key, retry_at, job_id)
redis.call('hmset', job_key,
'state', '"Delayed"',
'last_error', error_msg,
'failed_at', now
)
end
return 1