Skip to content Skip to sidebar Skip to footer

Google App Engine / Drive Sdk: Catching A Lot Http Deadline Exceptions

Our app is deployed on the Google App Engine, Python runtime (2.7) and is consuming the Drive API. More and more it catches HTTPException because of an exceeded deadline, on differ

Solution 1:

This blog post published in 2011 talks about how to catch DeadlineExceededError with metaclass instead of using decorators. I do not sure this guides or solves you, but gives you a idea that may be helpful.

from google.appengine.api import mail
from google.appengine.ext.deferred import defer
from google.appengine.ext.webapp import RequestHandler
from google.appengine.runtime import DeadlineExceededError
import sys
from traceback import format_exception
from SOME_APP_SPECIFIC_LIBRARY import serve_500
from LAST_POST import email_admins

class DecorateHttpVerbsMetaclass(type):

    def __new__(cls, name, bases, cls_attr):
        verbs = ['get', 'post', 'put', 'delete']
        for verb in verbs:
            if verb in cls_attr and isinstance(cls_attr[verb], function):
                cls_attr[verb] = deadline_decorator(cls_attr[verb])

        return super(DecorateHttpVerbsMetaclass, cls).__new__(cls, name,
                                                              bases, cls_attr)

class ExtendedHandler(RequestHandler):
    __metaclass__ = DecorateHttpVerbsMetaclass

    def handle_exception(self, exception, debug_mode):
        traceback_info = ''.join(format_exception(*sys.exc_info()))
        email_admins(traceback_info, defer_now=True)

        serve_500(self)

Post a Comment for "Google App Engine / Drive Sdk: Catching A Lot Http Deadline Exceptions"