GAE中的deferred.defer中的重试次数 [英] Retry count in deferred.defer in GAE

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

问题描述

我使用GAE的缓存的'资料库(python) ,如果发生异常,它会自动重试任务。



有没有一种方法可以知道(在任务处理函数中)任务被尝试的次数?

  if num_tries> 5:
email_admins()
提高deferred.PermanentTaskFailure

最初我以为我可以使用'TaskRetryOptions'来限制尝试,但我相信,不提供我的email_admins()调用的机制。还是呢?

当然,我可以读/写DB或memcache的尝试次数,但我更愿意避免这种复杂性。如果可能,我宁愿从任务/任务队列中获取详细信息。

解决方案

有几个标题会自动设置,任务
https://developers.google.com/appengine/docs/python/taskqueue/overview-push


X-AppEngine-TaskRetryCount,重试此任务的次数
;对于第一次尝试,此值为0.此数字包括由于缺少可用实例
且从未到达执行阶段而导致任务失败的
尝试。

X-AppEngine-TaskExecutionCount,这是执行阶段此任务先前失败的次数。此编号不包括由于缺少可用实例而导致的失败。




编辑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 task https://developers.google.com/appengine/docs/python/taskqueue/overview-push

X-AppEngine-TaskRetryCount, the number of times this task has been retried; for the first attempt, this value is 0. This number includes attempts where the task failed due to a lack of available instances and never reached the execution phase.

X-AppEngine-TaskExecutionCount, the number of times this task has previously failed during the execution phase. This number does not include failures due to a lack of available instances.

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中的重试次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆