mirror of https://github.com/rq/rq.git
Add dequeue method to Queue.
This commit is contained in:
parent
b5e0377eb0
commit
196a9815d2
|
@ -48,4 +48,3 @@ class job(object):
|
|||
return f.enqueue(self.queue, *args, **kwargs)
|
||||
f.delay = delay
|
||||
return f
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue