From 59d193590ce37950ffd305562b50f989a3050b03 Mon Sep 17 00:00:00 2001 From: Jean-Christophe SAAD-DUPUY Date: Thu, 13 Aug 2015 11:02:48 +0200 Subject: [PATCH] fix: remove recursive call to dequeue_any --- rq/queue.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index a4f57ab..1bc1fa3 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -367,25 +367,26 @@ class Queue(object): See the documentation of cls.lpop for the interpretation of timeout. """ - queue_keys = [q.key for q in queues] - result = cls.lpop(queue_keys, timeout, connection=connection) - if result is None: - return None - queue_key, job_id = map(as_text, result) - queue = cls.from_queue_key(queue_key, connection=connection) - try: - job = cls.job_class.fetch(job_id, connection=connection) - except NoSuchJobError: - # Silently pass on jobs that don't exist (anymore), - # and continue by reinvoking the same function recursively - return cls.dequeue_any(queues, timeout, connection=connection) - except UnpickleError as e: - # Attach queue information on the exception for improved error - # reporting - e.job_id = job_id - e.queue = queue - raise e - return job, queue + while True: + queue_keys = [q.key for q in queues] + result = cls.lpop(queue_keys, timeout, connection=connection) + if result is None: + return None + queue_key, job_id = map(as_text, result) + queue = cls.from_queue_key(queue_key, connection=connection) + try: + job = cls.job_class.fetch(job_id, connection=connection) + except NoSuchJobError: + # Silently pass on jobs that don't exist (anymore), + # and continue in the look + continue + except UnpickleError as e: + # Attach queue information on the exception for improved error + # reporting + e.job_id = job_id + e.queue = queue + raise e + return job, queue # Total ordering defition (the rest of the required Python methods are # auto-generated by the @total_ordering decorator)