|
|
@ -3,7 +3,7 @@ from .connections import resolve_connection
|
|
|
|
from .job import Job, Status
|
|
|
|
from .job import Job, Status
|
|
|
|
from .exceptions import (NoSuchJobError, UnpickleError,
|
|
|
|
from .exceptions import (NoSuchJobError, UnpickleError,
|
|
|
|
InvalidJobOperationError, DequeueTimeout)
|
|
|
|
InvalidJobOperationError, DequeueTimeout)
|
|
|
|
from .compat import total_ordering, string_types
|
|
|
|
from .compat import total_ordering, string_types, as_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_failed_queue(connection=None):
|
|
|
|
def get_failed_queue(connection=None):
|
|
|
@ -27,8 +27,9 @@ class Queue(object):
|
|
|
|
connection = resolve_connection(connection)
|
|
|
|
connection = resolve_connection(connection)
|
|
|
|
|
|
|
|
|
|
|
|
def to_queue(queue_key):
|
|
|
|
def to_queue(queue_key):
|
|
|
|
return cls.from_queue_key(queue_key, connection=connection)
|
|
|
|
return cls.from_queue_key(as_text(queue_key),
|
|
|
|
return map(to_queue, connection.keys('%s*' % prefix))
|
|
|
|
connection=connection)
|
|
|
|
|
|
|
|
return list(map(to_queue, connection.keys('%s*' % prefix)))
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def from_queue_key(cls, queue_key, connection=None):
|
|
|
|
def from_queue_key(cls, queue_key, connection=None):
|
|
|
@ -81,7 +82,8 @@ class Queue(object):
|
|
|
|
end = offset + (length - 1)
|
|
|
|
end = offset + (length - 1)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
end = length
|
|
|
|
end = length
|
|
|
|
return self.connection.lrange(self.key, start, end)
|
|
|
|
return [as_text(job_id) for job_id in
|
|
|
|
|
|
|
|
self.connection.lrange(self.key, start, end)]
|
|
|
|
|
|
|
|
|
|
|
|
def get_jobs(self, offset=0, length=-1):
|
|
|
|
def get_jobs(self, offset=0, length=-1):
|
|
|
|
"""Returns a slice of jobs in the queue."""
|
|
|
|
"""Returns a slice of jobs in the queue."""
|
|
|
@ -116,7 +118,7 @@ class Queue(object):
|
|
|
|
|
|
|
|
|
|
|
|
self.connection.rename(self.key, COMPACT_QUEUE)
|
|
|
|
self.connection.rename(self.key, COMPACT_QUEUE)
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
job_id = self.connection.lpop(COMPACT_QUEUE)
|
|
|
|
job_id = as_text(self.connection.lpop(COMPACT_QUEUE))
|
|
|
|
if job_id is None:
|
|
|
|
if job_id is None:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if Job.exists(job_id, self.connection):
|
|
|
|
if Job.exists(job_id, self.connection):
|
|
|
@ -204,7 +206,7 @@ class Queue(object):
|
|
|
|
|
|
|
|
|
|
|
|
def pop_job_id(self):
|
|
|
|
def pop_job_id(self):
|
|
|
|
"""Pops a given job ID from this Redis queue."""
|
|
|
|
"""Pops a given job ID from this Redis queue."""
|
|
|
|
return self.connection.lpop(self.key)
|
|
|
|
return as_text(self.connection.lpop(self.key))
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def lpop(cls, queue_keys, timeout, connection=None):
|
|
|
|
def lpop(cls, queue_keys, timeout, connection=None):
|
|
|
@ -274,7 +276,7 @@ class Queue(object):
|
|
|
|
result = cls.lpop(queue_keys, timeout, connection=connection)
|
|
|
|
result = cls.lpop(queue_keys, timeout, connection=connection)
|
|
|
|
if result is None:
|
|
|
|
if result is None:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
queue_key, job_id = result
|
|
|
|
queue_key, job_id = map(as_text, result)
|
|
|
|
queue = cls.from_queue_key(queue_key, connection=connection)
|
|
|
|
queue = cls.from_queue_key(queue_key, connection=connection)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
job = Job.fetch(job_id, connection=connection)
|
|
|
|
job = Job.fetch(job_id, connection=connection)
|
|
|
|