Add dequeue method to Queue.

This commit is contained in:
Vincent Driessen 2011-11-15 09:36:29 +01:00
parent b5e0377eb0
commit 196a9815d2
3 changed files with 14 additions and 1 deletions

View File

@ -48,4 +48,3 @@ class job(object):
return f.enqueue(self.queue, *args, **kwargs)
f.delay = delay
return f

View File

@ -1,3 +1,4 @@
from pickle import loads
from .proxy import conn
def to_queue_key(queue_name):
@ -30,5 +31,9 @@ class Queue(object):
def enqueue(self, job):
return job.enqueue(self)
def dequeue(self):
s = conn.lpop(self.key)
return loads(s)
def __str__(self):
return self.name

View File

@ -99,6 +99,15 @@ class TestQueue(RQTestCase):
self.assertEquals(q.empty, False)
self.assertQueueContains(q, testjob)
def test_dequeue(self):
"""Fetching work from specific queue."""
q = Queue('foo')
testjob.enqueue(q, 'Rick')
# Pull it off the queue (normally, a worker would do this)
f, rv_key, args, kwargs = q.dequeue()
self.assertEquals(f, testjob)
self.assertEquals(args[0], 'Rick')
class TestJob(RQTestCase):
def test_job_methods(self):