django-rq icon indicating copy to clipboard operation
django-rq copied to clipboard

After custom exception handler, if fail, how to put on failed

Open fchevitarese opened this issue 8 years ago • 2 comments

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.

fchevitarese avatar Jan 30 '17 13:01 fchevitarese

(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)

jsoa avatar Mar 12 '17 02:03 jsoa

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 ;)

fchevitarese avatar Mar 22 '17 12:03 fchevitarese