ThePloki ThePloki - 26 days ago 7
Python Question

GAE Python Deferred.defer set 'task_retry_limit' not working

I want my deferred task to only try once more after failing.

After reading this related question: Specifying retry limit for tasks queued using GAE deferred library it was obvious that I needed to follow the accepted answer, so I modified my code to look like this:

from google.appengine.ext import deferred

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


Now I get this error:

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'


Obviously im making a silly mistake, I just can't figure out what it is.

Answer

You need to pass a TaskRetryOptions instance, not just a dict:

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