diff --git a/rq/queue.py b/rq/queue.py index e9ac069..e6a8b0e 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -30,7 +30,7 @@ class Queue(object): def to_queue(queue_key): return cls.from_queue_key(as_text(queue_key), connection=connection) - return list(map(to_queue, connection.smembers(cls.redis_queues_keys))) + return [to_queue(rq_key) for rq_key in connection.smembers(cls.redis_queues_keys) if rq_key] @classmethod def from_queue_key(cls, queue_key, connection=None): @@ -52,7 +52,6 @@ class Queue(object): self._key = '%s%s' % (prefix, name) self._default_timeout = default_timeout self._async = async - self.connection.sadd(self.redis_queues_keys, self.key) @property def key(self): @@ -190,7 +189,10 @@ class Queue(object): the properties `origin` and `enqueued_at`. If Queue is instantiated with async=False, job is executed immediately. - """ + """ + # Add Queue key set + self.connection.sadd(self.redis_queues_keys, self.key) + if set_meta_data: job.origin = self.name job.enqueued_at = times.now() diff --git a/tests/test_queue.py b/tests/test_queue.py index 83e316b..bd8975b 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -256,13 +256,27 @@ class TestQueue(RQTestCase): q = Queue('first-queue') r = Queue('second-queue') s = Queue('third-queue') - all = Queue.all() - self.assertEquals(len(all), 3) - names = [q.name for q in all] + + # Ensure a queue is added only once a job is enqueued + self.assertEquals(len(Queue.all()), 0) + q.enqueue(say_hello) + self.assertEquals(len(Queue.all()), 1) + + # Ensure this holds true for multiple queues + r.enqueue(say_hello) + s.enqueue(say_hello) + names = [q.name for q in Queue.all()] + self.assertEquals(len(Queue.all()), 3) + + # Verify names self.assertTrue('first-queue' in names) self.assertTrue('second-queue' in names) self.assertTrue('third-queue' in names) + # Ensure we no longer return queues whose keys do not exist + self.testconn.srem(Queue.redis_queues_keys, s.key) + self.assertEquals(len(Queue.all()), 2) + class TestFailedQueue(RQTestCase): def test_requeue_job(self): """Requeueing existing jobs."""