diff --git a/rq/job.py b/rq/job.py index c073ced0..9de638e6 100644 --- a/rq/job.py +++ b/rq/job.py @@ -48,4 +48,3 @@ class job(object): return f.enqueue(self.queue, *args, **kwargs) f.delay = delay return f - diff --git a/rq/queue.py b/rq/queue.py index d1838056..0ad9270e 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -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 diff --git a/tests/test_rq.py b/tests/test_rq.py index 44615abf..bd7ba423 100644 --- a/tests/test_rq.py +++ b/tests/test_rq.py @@ -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):