local time = redis.call('TIME')
local now = time[1] * 1000 + math.floor(time[2] / 1000)
local due = redis.call('ZRANGEBYSCORE', KEYS[1], '-inf', now, 'WITHSCORES', 'LIMIT', 0, tonumber(ARGV[1]))
local nextEntry = redis.call('ZRANGE', KEYS[1], 0, 0, 'WITHSCORES')
local result = {tostring(now), nextEntry[2] or ''}
if ARGV[2] == 'SCHEDULE' then
result[#result + 1] = redis.call('HGET', KEYS[2], 'namespaceState') or 'ENABLED'
for index = 1, #due, 2 do
result[#result + 1] = due[index]
result[#result + 1] = due[index + 1]
result[#result + 1] = redis.call('HGET', ARGV[3] .. 'job:' .. due[index], 'definitionRevision') or ''
end
else
for index = 1, #due do
result[#result + 1] = due[index]
end
end
return result