I've set up my Python GAE app so that I get an email when a request handler raises an exception. To do this, I just subclass webapp2.RequestHandler
and override handle_exception
to send me an email with pertinent details.
Is it possible to get an email when a task in the task queue raises an exception?
EDIT: Adding more details since my original question wasn't clear. :)
I send myself an email for request handler exceptions using the following code:
class MyRequestHandler(webapp2.RequestHandler):
def handle_exception(self, exception, debug_mode):
...
mail.send_mail_to_admins(sender="me@example.com", ...)
...
In this way, I get an email for any exception raised by a request handler.
I would also like to get emails for exceptions raised when I submit tasks using the deferred library. In this case, I don't think I can use a custom request handler. I suppose I could put a wrapper function around all my calls to deferred.defer()
:
def my_deferred(...):
try:
deferred.defer(...)
except Exception, msg:
mail.send_mail_to_admins(sender="me@example.com", ...)
Is there a better way to accomplish this?