Google App Engine / Drive SDK: catching a lot HTTP Deadline exceptions

前端 未结 1 1716
我寻月下人不归
我寻月下人不归 2021-02-06 13:11

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 dea

相关标签:
1条回答
  • 2021-02-06 13:36

    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)
    
    0 讨论(0)
提交回复
热议问题