diff --git a/rq/queue.py b/rq/queue.py index 277dcef1..96851d03 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -1096,6 +1096,11 @@ class Queue: """ job.origin = self.name job = self.setup_dependencies(job, pipeline=pipeline) + # Add Queue key set + pipe = pipeline if pipeline is not None else self.connection.pipeline() + pipe.sadd(self.redis_queues_keys, self.key) + if pipeline is None: + pipe.execute() # If we do not depend on an unfinished job, enqueue the job. if job.get_status(refresh=False) != JobStatus.DEFERRED: return self._enqueue_job(job, pipeline=pipeline, at_front=at_front) @@ -1116,8 +1121,6 @@ class Queue: """ pipe = pipeline if pipeline is not None else self.connection.pipeline() - # Add Queue key set - pipe.sadd(self.redis_queues_keys, self.key) job.redis_server_version = self.get_redis_server_version() job.set_status(JobStatus.QUEUED, pipeline=pipe) diff --git a/tests/test_queue.py b/tests/test_queue.py index 46f597e3..57a21008 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -458,6 +458,21 @@ class TestQueue(RQTestCase): self.assertEqual(len(queues), 1) self.assertIs(queues[0].job_class, CustomJob) + def test_all_queues_with_only_deferred_jobs(self): + """All queues with only deferred jobs""" + queue_with_queued_jobs = Queue('queue_with_queued_jobs', connection=self.connection) + queue_with_deferred_jobs = Queue('queue_with_deferred_jobs', connection=self.connection) + + parent_job = queue_with_queued_jobs.enqueue(say_hello) + queue_with_deferred_jobs.enqueue(say_hello, depends_on=parent_job) + + # Ensure all queues are listed + self.assertEqual(len(Queue.all(connection=self.connection)), 2) + names = [q.name for q in Queue.all(connection=self.connection)] + # Verify names + self.assertTrue('queue_with_queued_jobs' in names) + self.assertTrue('queue_with_deferred_jobs' in names) + def test_from_queue_key(self): """Ensure being able to get a Queue instance manually from Redis""" q = Queue(connection=self.connection)