GAE Python Deferred.defer设置' task_retry_limit'不工作

时间:2016-11-11 17:53:39

标签: python google-app-engine

我希望我的延期任务在失败后再尝试一次。

阅读完相关问题之后:Specifying retry limit for tasks queued using GAE deferred library很明显我需要遵循接受的答案,所以我将代码修改为:

from google.appengine.ext import deferred

deferred.defer(MyFunction, DATA, _retry_options={'task_retry_limit': 1})

现在我收到了这个错误:

File "/usr/local/google-cloud-sdk/platform/google_appengine/google/appengine/ext/deferred/deferred.py", line 269, in defer
    return task.add(queue, transactional=transactional)
File "/usr/local/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue.py", line 1143, in add
    return self.add_async(queue_name, transactional).get_result()
File "/usr/local/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue.py", line 1139, in add_async
    return Queue(queue_name).add_async(self, transactional, rpc)
File "/usr/local/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue.py", line 1889, in add_async
rpc)
File "/usr/local/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue.py", line 2008, in __AddTasks
    fill_request(task, request.add_add_request(), transactional)
File "/usr/local/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue.py", line 2093, in __FillAddPushTasksRequest
    task.retry_options, task_request.mutable_retry_parameters())
File "/usr/local/google-cloud-sdk/platform/google_appengine/google/appengine/api/taskqueue/taskqueue.py", line 2033, in __FillTaskQueueRetryParameters
    if retry_options.min_backoff_seconds is not None:
AttributeError: 'dict' object has no attribute 'min_backoff_seconds'

显然我犯了一个愚蠢的错误,我只是无法弄清楚它是什么。

1 个答案:

答案 0 :(得分:2)

您需要传递TaskRetryOptions实例,而不仅仅是dict:

from google.appengine.ext import deferred
from google.appengine.api.taskqueue import TaskRetryOptions

options = TaskRetryOptions(task_retry_limit=1)
deferred.defer(MyFunction, DATA, _retry_options=options)