【问题标题】:Reducing Log Clutter via ndb.add_flow_exception with deferred tasks通过带有延迟任务的 ndb.add_flow_exception 减少日志混乱
【发布时间】:2014-04-24 16:58:24
【问题描述】:

我正在寻找减少错误日志混乱的方法。

“浪费性异常日志记录”最令人沮丧的用例之一是任务队列任务失败。

当然,对于该特定示例,一个好的解决方案是 self.error(500) 而不是 raise Exception - 但此解决方案不适用于 deferred.defer

我知道重新触发延迟任务的唯一方法是将Exception 提高到 webapp 处理程序。

记录的解决方案如下所示:

class CompletedExpectedException(Exception):
    """This Exception is completely expected. 
    We don't need to see it as "errors" in the logs, or GAE dashboard graphs."""
    pass

# The following code, when on the 'global' app level, does not have an effect.
ndb.add_flow_exception(CompletedExpectedException)

# The following code does not work, either
class WarmupHandler(webapp2.RequestHandler):
    """/_ah/warmup or /_ah/start"""
    def get(self):
        ndb.add_flow_exception(CompletedExpectedException)

    def post(self):
        self.get()

除了将我的解决方案移至taskqueue 而不是deferred.defer - 还有哪些解决方案?

【问题讨论】:

    标签: python google-app-engine app-engine-ndb


    【解决方案1】:

    add_flow_exception 只是 NDB 的东西,它没有与任何更高级别的东西挂钩,所以除非它是 tasklet 中的代码引发异常,否则我认为它对您没有帮助。

    从延迟函数中,您可以提高 deferred.SingularTaskFailure 以避免记录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多