|
|
@ -76,6 +76,7 @@ class Queue(object):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
job = Job.safe_fetch(job_id, connection=self.connection)
|
|
|
|
job = Job.safe_fetch(job_id, connection=self.connection)
|
|
|
|
except NoSuchJobError:
|
|
|
|
except NoSuchJobError:
|
|
|
|
|
|
|
|
self.remove(job_id)
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
except UnpickleError:
|
|
|
|
except UnpickleError:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
@ -88,6 +89,11 @@ class Queue(object):
|
|
|
|
"""Returns a count of all messages in the queue."""
|
|
|
|
"""Returns a count of all messages in the queue."""
|
|
|
|
return self.connection.llen(self.key)
|
|
|
|
return self.connection.llen(self.key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove(self, job_or_id):
|
|
|
|
|
|
|
|
"""Removes Job from queue, accepts either a Job instance or ID."""
|
|
|
|
|
|
|
|
job_id = job_or_id.id if isinstance(job_or_id, Job) else job_or_id
|
|
|
|
|
|
|
|
return self.connection._lrem(self.key, 0, job_id)
|
|
|
|
|
|
|
|
|
|
|
|
def compact(self):
|
|
|
|
def compact(self):
|
|
|
|
"""Removes all "dead" jobs from the queue by cycling through it, while
|
|
|
|
"""Removes all "dead" jobs from the queue by cycling through it, while
|
|
|
|
guarantueeing FIFO semantics.
|
|
|
|
guarantueeing FIFO semantics.
|
|
|
@ -316,11 +322,11 @@ class FailedQueue(Queue):
|
|
|
|
job = Job.fetch(job_id, connection=self.connection)
|
|
|
|
job = Job.fetch(job_id, connection=self.connection)
|
|
|
|
except NoSuchJobError:
|
|
|
|
except NoSuchJobError:
|
|
|
|
# Silently ignore/remove this job and return (i.e. do nothing)
|
|
|
|
# Silently ignore/remove this job and return (i.e. do nothing)
|
|
|
|
self.connection._lrem(self.key, 0, job_id)
|
|
|
|
self.remove(job_id)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# Delete it from the failed queue (raise an error if that failed)
|
|
|
|
# Delete it from the failed queue (raise an error if that failed)
|
|
|
|
if self.connection._lrem(self.key, 0, job.id) == 0:
|
|
|
|
if self.remove(job) == 0:
|
|
|
|
raise InvalidJobOperationError('Cannot requeue non-failed jobs.')
|
|
|
|
raise InvalidJobOperationError('Cannot requeue non-failed jobs.')
|
|
|
|
|
|
|
|
|
|
|
|
job.status = Status.QUEUED
|
|
|
|
job.status = Status.QUEUED
|
|
|
|