django-rq
django-rq copied to clipboard
After custom exception handler, if fail, how to put on failed
Hello all. I've writed a custom exception handler and i'm retrying some jobs after a count number of failures.
After that max_retries reaches the limit, i want to put them in the failed queue.
I didn't figured out how this behavior should be implemented. After retry, im returning an exception MaxTriesReached, and checking it on my custom exception. If it's that, should go to failed.
But not happening...
Anyone have some scenario to help me out ? Thanks in advance.
(assuming you mean "should go to failed queue")
I ran into a similar issue recently, I got around it by adding a second exception handler that moves to the failed queue...
RQ_EXCEPTION_HANDLERS = [
'myapp.job_exception_handler',
'myapp.move_to_failed_queue']
def move_to_failed_queue(job, *exc_info):
worker = get_worker(job.origin)
worker.move_to_failed_queue(job, *exc_info)
return True
if you don't want everything moving to the failed queue you can keep just the one custom exception handler and do the move there...
RQ_EXCEPTION_HANDLERS = [
'myapp.job_exception_handler']
def job_exception_handler(job, *exc_info):
# ...
# exception handler logic
# ...
worker = get_worker(job.origin)
worker.move_to_failed_queue(job, *exc_info)
Thank @jsoa. I will put this logic inside my exception and when i face this, i can put the job into failed from there ;)
Will test it ... Thanks once again ;)