mirror of https://github.com/rq/rq.git
Simplify enqueue_waitlist by using lpop.
This commit is contained in:
parent
18ff57ef35
commit
0dfb041383
|
@ -425,14 +425,6 @@ class Job(object):
|
|||
# TODO: This can probably be pipelined
|
||||
self.connection.rpush(Job.waitlist_key_for(self._parent_id), self.id)
|
||||
|
||||
def get_waitlist(self):
|
||||
"""Returns all job ids in the waitlist.
|
||||
"""
|
||||
# TODO: This can probably be pipelined
|
||||
|
||||
return self.connection.lrange(
|
||||
self.waitlist_key, 0, self.connection.llen(self.waitlist_key) - 1)
|
||||
|
||||
def __str__(self):
|
||||
return '<Job %s: %s>' % (self.id, self.description)
|
||||
|
||||
|
|
|
@ -216,12 +216,12 @@ class Queue(object):
|
|||
def enqueue_waitlist(self, job):
|
||||
"""Enqueues all jobs in the waitlist and clears it"""
|
||||
# TODO: can probably be pipelined
|
||||
job_ids = job.get_waitlist()
|
||||
for job_id in job.get_waitlist():
|
||||
while True:
|
||||
job_id = self.connection.lpop(job.waitlist_key)
|
||||
if job_id is None:
|
||||
break
|
||||
waitlisted_job = Job.fetch(job_id, connection=self.connection)
|
||||
self.enqueue_job(waitlisted_job)
|
||||
if job_ids:
|
||||
self.connection.delete(job.waitlist_key)
|
||||
|
||||
def pop_job_id(self):
|
||||
"""Pops a given job ID from this Redis queue."""
|
||||
|
|
|
@ -273,12 +273,3 @@ class TestJob(RQTestCase):
|
|||
job.save()
|
||||
job.register_dependency()
|
||||
self.assertEqual(self.testconn.lpop('rq:job:id:waitlist'), job.id)
|
||||
|
||||
def test_get_waitlist(self):
|
||||
"""Test that all waitlisted job ids are fetched"""
|
||||
job = Job.create(func=say_hello)
|
||||
self.assertEqual(job.get_waitlist(), [])
|
||||
self.testconn.lpush(job.waitlist_key, 'id_1')
|
||||
self.assertEqual(job.get_waitlist(), ['id_1'])
|
||||
self.testconn.lpush(job.waitlist_key, 'id_2')
|
||||
self.assertEqual(job.get_waitlist(), ['id_2', 'id_1'])
|
||||
|
|
Loading…
Reference in New Issue