为使用GAE延迟库排队的任务指定重试限制

2024-10-03 15:27:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我们正在使用GAEdeferred library卸载某些耗时的任务,并想知道如何为这些卸载的任务设置重试限制。我们遇到了这样的问题:由于某些不可恢复的异常,某些任务将永远无法成功执行。在


Tags: library耗时gaedeferred
3条回答

根据the documentation,可以使用deferred.deferAPI的_retry_options将重试选项传递给关联的Task()实例:

_countdown, _eta, _headers, _name, _target, _transactional, _url, _retry_options, _queue: Passed through to the task queue - see the task queue documentation for details.

the ^{} doc

enter image description here

。。。在

enter image description here

您可以使用^{}task_retry_limit属性:

task_retry_limit

The maximum number of retry attempts for a failed task.

In push queues, the counter is incremented each time App Engine tries the task, up to the specified task_retry_limit. If specified with task_age_limit, App Engine retries the task until both limits are reached.

In pull queues, the counter is incremented each time the task is leased, up to the specified task_retry_limit. Tasks are deleted automatically once they have been leased the number of times specified in the limit.

注意:答案仅基于文档,我没有实际实现,YMMV。在

根据documentation

queue:
- name: fooqueue
  rate: 1/s
  retry_parameters:
    task_retry_limit: 7
    task_age_limit: 2d
- name: barqueue
  rate: 1/s
  retry_parameters:
    min_backoff_seconds: 10
    max_backoff_seconds: 200
    max_doublings: 0
- name: bazqueue
  rate: 1/s
  retry_parameters:
    min_backoff_seconds: 10
    max_backoff_seconds: 200
    max_doublings: 3

检查任务中的http头值。在

如果你不想重试一个任务,你可以提出延迟。永久任务失败例外。将只记录此异常,任务不会再次运行。在

访问http标头的不同方法:

对于由taskqueue触发的http处理程序: 尝试次数=self.request.headers.get('X-AppEngine-taskrytycount')

对于延迟库触发的函数: num_tries=webapp2.get_request()。标题.get('X-AppEngine-taskrytycount')

相关问题 更多 >