Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ function Qless.jobs(now, state, ...)
return queue.locks.peek(now, offset, count)
elseif state == 'stalled' then
return queue.locks.expired(now, offset, count)
elseif state == 'waiting' then
return queue.work.peek(now, offset, count)
elseif state == 'scheduled' then
queue:check_scheduled(now, queue.scheduled.length())
return queue.scheduled.peek(now, offset, count)
Expand Down
8 changes: 4 additions & 4 deletions queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ function Qless.queue(name)

-- Access to our work
queue.work = {
peek = function(count)
peek = function(now, offset, count)
if count == 0 then
return {}
end
local jids = {}
for index, jid in ipairs(redis.call(
'zrevrange', queue:prefix('work'), 0, count - 1)) do
'zrevrange', queue:prefix('work'), offset, offset + count - 1)) do
table.insert(jids, jid)
end
return jids
Expand Down Expand Up @@ -247,7 +247,7 @@ function QlessQueue:peek(now, count)

-- With these in place, we can expand this list of jids based on the work
-- queue itself and the priorities therein
table.extend(jids, self.work.peek(count - #jids))
table.extend(jids, self.work.peek(now, 0, count - #jids))

return jids
end
Expand Down Expand Up @@ -322,7 +322,7 @@ function QlessQueue:pop(now, worker, count)

-- With these in place, we can expand this list of jids based on the work
-- queue itself and the priorities therein
table.extend(jids, self.work.peek(count - #jids))
table.extend(jids, self.work.peek(now, 0, count - #jids))

local state
for index, jid in ipairs(jids) do
Expand Down
11 changes: 11 additions & 0 deletions test/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ def test_pagination_running(self):
self.assertEqual(
self.lua('jobs', 100, 'running', 'queue', 50, 50), jids[50:])

def test_pagination_waiting(self):
'''Jobs should be able to provide paginated result for waiting'''
jids = map(str, range(100))
for jid in jids:
self.lua('put', jid, 'worker', 'queue', jid, 'klass', {}, 0)
# Get two pages and ensure they're what we expect
self.assertEqual(
self.lua('jobs', 100, 'waiting', 'queue', 0, 50), jids[:50])
self.assertEqual(
self.lua('jobs', 100, 'waiting', 'queue', 50, 50), jids[50:])


class TestQueue(TestQless):
'''Test queue info tests'''
Expand Down