Sha256: 87f5002cb8af9904327111d9b3a182ba016df7600fc915530dc814cf75964fcd

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

-- Jobs(0, 'complete' | (('stalled' | 'running' | 'scheduled' | 'depends', 'recurring'), now, queue) [offset, [count]])
-- -------------------------------------------------------------------------------------------------------
-- 
-- Return all the job ids currently considered to be in the provided state
-- in a particular queue. The response is a list of job ids:
-- 
-- 	[
--		jid1, 
--		jid2,
--		...
--	]

if #KEYS > 0 then
	error('Jobs(): Got '.. #KEYS .. ' expected 0 KEYS arguments')
end

local t      = assert(ARGV[1]                , 'Jobs(): Arg "type" missing')
if t == 'complete' then
	local offset = assert(tonumber(ARGV[2] or 0) , 'Jobs(): Arg "offset" not a number: ' .. tostring(ARGV[2]))
	local count  = assert(tonumber(ARGV[3] or 25), 'Jobs(): Arg "count" not a number: ' .. tostring(ARGV[3]))
	return redis.call('zrevrange', 'ql:completed', offset, offset + count - 1)
else
	local now    = assert(tonumber(ARGV[2])      , 'Jobs(): Arg "now" missing or not a number: ' .. tostring(ARGV[2]))
	local queue  = assert(ARGV[3]                , 'Jobs(): Arg "queue" missing')
	local offset = assert(tonumber(ARGV[4] or 0) , 'Jobs(): Arg "offset" not a number: ' .. tostring(ARGV[4]))
	local count  = assert(tonumber(ARGV[5] or 25), 'Jobs(): Arg "count" not a number: ' .. tostring(ARGV[5]))

	if t == 'running' then
		return redis.call('zrangebyscore', 'ql:q:' .. queue .. '-locks', now, 133389432700, 'limit', offset, count)
	elseif t == 'stalled' then
		return redis.call('zrangebyscore', 'ql:q:' .. queue .. '-locks', 0, now, 'limit', offset, count)
	elseif t == 'scheduled' then
		return redis.call('zrange', 'ql:q:' .. queue .. '-scheduled', offset, offset + count - 1)
	elseif t == 'depends' then
		return redis.call('zrange', 'ql:q:' .. queue .. '-depends', offset, offset + count - 1)
	elseif t == 'recurring' then
		return redis.call('zrange', 'ql:q:' .. queue .. '-recur', offset, offset + count - 1)
	else
		error('Jobs(): Unknown type "' .. t .. '"')
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qless-0.9.3 lib/qless/qless-core/jobs.lua
qless-0.9.2 lib/qless/qless-core/jobs.lua
qless-0.9.1 lib/qless/qless-core/jobs.lua