From 0dfb0413831c2df1df451fa50ffafdc85e0cbd78 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Sun, 28 Apr 2013 11:20:39 +0700 Subject: [PATCH] Simplify enqueue_waitlist by using lpop. --- rq/job.py | 8 -------- rq/queue.py | 8 ++++---- tests/test_job.py | 9 --------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/rq/job.py b/rq/job.py index 2a6efcf..fbaa424 100644 --- a/rq/job.py +++ b/rq/job.py @@ -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 '' % (self.id, self.description) diff --git a/rq/queue.py b/rq/queue.py index da0154a..e06904d 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -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.""" diff --git a/tests/test_job.py b/tests/test_job.py index 87f649e..cafc8ad 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -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'])