I have a website running on Heroku in Python, and I have a worker up as a background process to handle tasks that I don't want to block webpage delivery and therefore are inappropriate for the web
dynos. For this, I've set up a queue using rq
and redis.
In my process, occasionally, custom exceptions might arise. For a specific subset of these, rather than allow the job to go straight to the 'failed' queue, I want to requeue it a few times. I've been looking at the exception handlers page on the rq
homepage, and I'm unclear on a few things. In particular, it describes the following way to write an exception handler:
def my_handler(job, exc_type, exc_value, traceback):
# do custom things here
# for example, write the exception info to a DB
...
Right now, I'm planning to do something along the lines of:
from rq import requeue_job
def my_handler(job, exc_type, exc_value, traceback):
if exec_type == "MyCustomError":
job.meta['MyErrorCount'] += 1
job.save()
if job.meta['MyErrorCount'] >= 10:
return True
else:
requeue_job(job.id)
return False
Questions:
- What kinds of objects are
exc_type
,exc_value
, andtraceback
? (e.g., is the lineif exec_type == "MyCustomError"
at all correct?) - Will my error handler effectively detect if it's a specific error, requeue those jobs until it fails 10 times, and then let it fall to
failed
? Will it also let all other errors fall tofailed
?