问题描述
我使用GAE的'资料库(python) ,如果发生异常,它会自动重试任务。
有没有一种方法可以知道(在任务处理函数中)任务被尝试的次数?
if num_tries> 5:
email_admins()
提高deferred.PermanentTaskFailure
最初我以为我可以使用'TaskRetryOptions'来限制尝试,但我相信,不提供我的email_admins()调用的机制。还是呢?
当然,我可以读/写DB或memcache的尝试次数,但我更愿意避免这种复杂性。如果可能,我宁愿从任务/任务队列中获取详细信息。
有几个标题会自动设置,任务
编辑1
这些值可以访问:
num_tries = self.request.headers.get('X-AppEngine-TaskRetryCount' )
编辑2
http://webapp-improved.appspot.com/api/webapp2.html#webapp2。 for defered try: webapp2.get_request() I'm using GAE's 'deffered' library (python), which automatically retries the task in the event an exception is raised. Is there a way to know (within the task handler function) the number of times the task has been tried? My end goal is to implement something like: Initially I thought I could use 'TaskRetryOptions' to limit the number of tries, but I believe that doesnt provide a mechanism for my email_admins() call. Or does it? [edit] of course I could read/write the number of tries to the DB or memcache, but I'd prefer to avoid that complexity. I'd prefer to get the details from the task / task queue if possible. There are several headers will be set automatically with taskhttps://developers.google.com/appengine/docs/python/taskqueue/overview-push These values can access: http://webapp-improved.appspot.com/api/webapp2.html#webapp2.get_request for defered try: 这篇关于GAE中的deferred.defer中的重试次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
if num_tries >5:
email_admins()
raise deferred.PermanentTaskFailure
EDIT 1
num_tries = self.request.headers.get('X-AppEngine-TaskRetryCount')
EDIT 2
request = webapp2.get_request()