local currentSource = redis.call('HGET', KEYS[3], 'schedulerQualifier')
if currentSource and currentSource ~= '' and currentSource ~= ARGV[25] then
return {'SOURCE_MISMATCH', currentSource}
end
local currentRevision = redis.call('HGET', KEYS[3], 'definitionRevision')
if currentRevision then
local requestedRevision = tonumber(ARGV[2])
if redis.call('HGET', KEYS[3], 'state') == 'DELETED' and requestedRevision <= tonumber(currentRevision) then
return {'DELETED', currentRevision}
end
if tonumber(currentRevision) > requestedRevision then
return {'STALE', currentRevision}
end
if tonumber(currentRevision) == requestedRevision then
local currentDigest = redis.call('HGET', KEYS[3], 'definitionDigest')
if currentDigest ~= ARGV[3] then
redis.call('HSET', KEYS[3], 'state', 'CONFLICT')
redis.call('ZREM', KEYS[2], ARGV[1])
return {'CONFLICT', currentRevision}
end
if not currentSource or currentSource == '' then
redis.call('HSET', KEYS[3], 'schedulerQualifier', ARGV[25])
end
return {'ADOPTED', currentRevision}
end
end
redis.call('SADD', KEYS[1], ARGV[1])
redis.call('HSET', KEYS[3],
'schedulerQualifier', ARGV[25],
'jobName', ARGV[1],
'definitionRevision', ARGV[2],
'definitionDigest', ARGV[3],
'state', ARGV[4],
'scheduleShard', ARGV[5],
'workerName', ARGV[6],
'workerKey', ARGV[7],
'trigger', ARGV[8],
'scheduleType', ARGV[9],
'cron', ARGV[10],
'zone', ARGV[11],
'intervalMs', ARGV[12],
'concurrency', ARGV[13],
'misfire', ARGV[14],
'timeoutMs', ARGV[15],
'maxAttempts', ARGV[16],
'retryDelayMs', ARGV[17],
'contractRevision', ARGV[18],
'schemaId', ARGV[19],
'wireCodecs', ARGV[20],
'fanoutReceiptTimeoutMs', ARGV[21],
'fanoutReceiptMaxRetries', ARGV[22],
'fanoutFailurePolicy', ARGV[23],
'nextFireAt', ARGV[24])
redis.call('HDEL', KEYS[3], 'deletedAt', 'tombstoneUntil')
if ARGV[4] == 'ENABLED' and tonumber(ARGV[24]) > 0 then
redis.call('ZADD', KEYS[2], ARGV[24], ARGV[1])
else
redis.call('ZREM', KEYS[2], ARGV[1])
end
return {'OK', ARGV[2]}