From 5989228330a45b19eba248cec81d7c6170d2d80f Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Tue, 8 May 2012 16:39:09 +0700 Subject: [PATCH] Queue.lpop should take connection as argument. --- rq/queue.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index 3377be8..8b34573 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -154,7 +154,7 @@ class Queue(object): return self.connection.lpop(self.key) @classmethod - def lpop(cls, queue_keys, blocking): + def lpop(cls, queue_keys, blocking, connection=None): """Helper method. Intermediate method to abstract away from some Redis API details, where LPOP accepts only a single key, whereas BLPOP accepts multiple. So if we want the non-blocking LPOP, we need to @@ -163,13 +163,14 @@ class Queue(object): Until Redis receives a specific method for this, we'll have to wrap it this way. """ - conn = get_current_connection() + if connection is None: + connection = get_current_connection() if blocking: - queue_key, job_id = conn.blpop(queue_keys) + queue_key, job_id = connection.blpop(queue_keys) return queue_key, job_id else: for queue_key in queue_keys: - blob = conn.lpop(queue_key) + blob = connection.lpop(queue_key) if blob is not None: return queue_key, blob return None @@ -205,7 +206,7 @@ class Queue(object): any of the queues, or returns None. """ queue_keys = [q.key for q in queues] - result = cls.lpop(queue_keys, blocking) + result = cls.lpop(queue_keys, blocking, connection=connection) if result is None: return None queue_key, job_id = result