Created
May 1, 2013 21:30
-
-
Save jokull/5498543 to your computer and use it in GitHub Desktop.
Example of an RQ exception handler that allows three failures before moving to the failed queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
queues = [] | |
def retry_handler(job, exc_type, exc_value, traceback): | |
# Returning True moves the job to the failed queue (or continue to | |
# the next handler) | |
job.meta.setdefault('failures', 1) | |
job.meta['failures'] += 1 | |
if job.meta['failures'] > 3 or isinstance(exc_type, (LookupError, CorruptImageError)): | |
job.save() | |
return True | |
job.status = Status.QUEUED | |
for queue_ in queues: | |
if queue_.name == job.origin: | |
queue_.enqueue_job(job, timeout=job.timeout) | |
break | |
else: | |
return True # Queue has disappeared, fail job | |
return False # Job is handled. Stop the handler chain. | |
queues.append(Queue(exc_handler=retry_handler)) |
I found status: from rq.job import Status
queues come from Queue
from rq import Queue
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where does STATUS and queues come from?