diff --git a/rq/job.py b/rq/job.py index ce3fc6b..97d5161 100644 --- a/rq/job.py +++ b/rq/job.py @@ -424,14 +424,14 @@ class Job(object): def register_dependency(self): """Jobs may have a waitlist. Jobs in this waitlist are enqueued only if the dependency job is successfully performed. We maintain this - waitlist in Redis, with key that looks something like: + waitlist in a Redis set, with key that looks something like: - rq:job:job_id:waitlist = ['job_id_1', 'job_id_2'] + rq:job:job_id:waitlist = {'job_id_1', 'job_id_2'} This method puts the job on it's dependency's waitlist. """ # TODO: This can probably be pipelined - self.connection.rpush(Job.waitlist_key_for(self._dependency_id), self.id) + self.connection.sadd(Job.waitlist_key_for(self._dependency_id), self.id) def __str__(self): return '' % (self.id, self.description) diff --git a/rq/queue.py b/rq/queue.py index 4c1196a..70f4094 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -247,7 +247,7 @@ class Queue(object): """Enqueues all jobs in the waitlist and clears it""" # TODO: can probably be pipelined while True: - job_id = as_text(self.connection.lpop(job.waitlist_key)) + job_id = as_text(self.connection.spop(job.waitlist_key)) if job_id is None: break waitlisted_job = Job.fetch(job_id, connection=self.connection) diff --git a/tests/test_job.py b/tests/test_job.py index 039e9d3..73966db 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -289,4 +289,4 @@ class TestJob(RQTestCase): job._dependency_id = 'id' job.save() job.register_dependency() - self.assertEqual(as_text(self.testconn.lpop('rq:job:id:waitlist')), job.id) + self.assertEqual(as_text(self.testconn.spop('rq:job:id:waitlist')), job.id) diff --git a/tests/test_queue.py b/tests/test_queue.py index 306261f..c7602a7 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -304,7 +304,7 @@ class TestQueue(RQTestCase): # After waitlist is enqueued, job_1 and job_2 should be in queue self.assertEqual(q.job_ids, []) q.enqueue_waitlist(parent_job) - self.assertEqual(q.job_ids, [job_1.id, job_2.id]) + self.assertEqual(set(q.job_ids), set([job_1.id, job_2.id])) self.assertFalse(self.testconn.exists(parent_job.waitlist_key)) def test_enqueue_job_with_dependency(self):