Reputation: 16563
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="[email protected]", ...)
...
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="[email protected]", ...)
Is there a better way to accomplish this?
Upvotes: 0
Views: 117
Reputation: 16890
Task queue requests are handled exactly the same way as regular requests, so you should be able to use the same approach. (Of course this does not apply when the task queue doesn't get to submit the request to your handler. But that should be rare. And I can't tell from your question what kind of error you see in the logs that you'd like to receive email about. More detailed questions get better answers. :-)
Upvotes: 2