本文介绍了GAE中的deferred.defer中的重试次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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:

if num_tries >5:
  email_admins()
  raise deferred.PermanentTaskFailure

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

EDIT 1

These values can access:

num_tries  = self.request.headers.get('X-AppEngine-TaskRetryCount')

EDIT 2

http://webapp-improved.appspot.com/api/webapp2.html#webapp2.get_request

for defered try:

request = webapp2.get_request()

这篇关于GAE中的deferred.defer中的重试次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 00:58