使用延迟任务通过ndb.add_flow_exception减少Log Clutter

时间:2014-04-24 16:58:25

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

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

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

当然,针对该特定示例的一个很好的解决方案是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之外 - 还有哪些解决方案?

1 个答案:

答案 0 :(得分:1)

add_flow_exception只是一个NDB的东西,它没有挂钩到任何更高级别的东西,所以除非它tasklet中的代码提出异常,我不认为它可以帮到你。

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

相关问题