Queue.lpop should take connection as argument.

main
Selwin Ong 13 years ago
parent 1d27223069
commit 5989228330

@ -154,7 +154,7 @@ class Queue(object):
return self.connection.lpop(self.key) return self.connection.lpop(self.key)
@classmethod @classmethod
def lpop(cls, queue_keys, blocking): def lpop(cls, queue_keys, blocking, connection=None):
"""Helper method. Intermediate method to abstract away from some """Helper method. Intermediate method to abstract away from some
Redis API details, where LPOP accepts only a single key, whereas BLPOP 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 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 Until Redis receives a specific method for this, we'll have to wrap it
this way. this way.
""" """
conn = get_current_connection() if connection is None:
connection = get_current_connection()
if blocking: if blocking:
queue_key, job_id = conn.blpop(queue_keys) queue_key, job_id = connection.blpop(queue_keys)
return queue_key, job_id return queue_key, job_id
else: else:
for queue_key in queue_keys: for queue_key in queue_keys:
blob = conn.lpop(queue_key) blob = connection.lpop(queue_key)
if blob is not None: if blob is not None:
return queue_key, blob return queue_key, blob
return None return None
@ -205,7 +206,7 @@ class Queue(object):
any of the queues, or returns None. any of the queues, or returns None.
""" """
queue_keys = [q.key for q in queues] 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: if result is None:
return None return None
queue_key, job_id = result queue_key, job_id = result

Loading…
Cancel
Save