问题
I'm seeing a buggy behaviour in taskqueue API. When a task fails, appengine always runs it once again, even if I tell it not to.
This is the relevant code:
NO_RETRY = TaskRetryOptions(task_retry_limit=0)
class EnqueueTaskDapau(webapp2.RequestHandler):
def get(self):
taskqueue.add(
url='/task_dapau',
queue_name='DEFAULT',
retry_options=NO_RETRY
)
class TaskDapau(webapp2.RequestHandler):
def get(self):
logging.warning('Vai dar pau')
raise BaseException('Deu pau :-)')
def post(self):
return self.get()
application = webapp2.WSGIApplication([
('/', MainPage),
('/enqueue_dapau', EnqueueTaskDapau),
('/task_dapau', TaskDapau),
], debug=True)
The whole app is available on Github so it should be easy to reproduce. When I point my browser to /enqueue_dapau, this is what I see in the logs (on the web console):
2014-10-30 08:31:01.054 /task_dapau 500 4ms 0kb AppEngine-Google; (+http://code.google.com/appengine) module=default version=1
W 2014-10-30 08:31:01.052 Vai dar pau
E 2014-10-30 08:31:01.053 Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in
2014-10-30 08:31:00.933 /task_dapau 500 3ms 0kb AppEngine-Google; (+http://code.google.com/appengine) module=default version=1
W 2014-10-30 08:31:00.931 Vai dar pau
E 2014-10-30 08:31:00.932 Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in
2014-10-30 08:31:00.897 /enqueue_dapau 200 91ms 0kb Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36 module=default version=1
If I look at Task Queues on the web console, I see "Run in Last Minute == 2" This behaviour is different from what I get locally with the SDK:
INFO 2014-10-30 15:49:05,711 module.py:666] default: "GET /enqueue_dapau HTTP/1.1" 200 -
WARNING 2014-10-30 15:49:05,729 views.py:33] Vai dar pau
ERROR 2014-10-30 15:49:05,729 wsgi.py:279]
Traceback (most recent call last):
File "/home/tony/google_appengine/google/appengine/runtime/wsgi.py", line 267, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/home/tony/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/home/tony/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/tony/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/home/tony/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/home/tony/work/qmag/gaetests/src/views.py", line 37, in post
return self.get()
File "/home/tony/work/qmag/gaetests/src/views.py", line 34, in get
raise BaseException('Deu pau :-)')
BaseException: Deu pau :-)
INFO 2014-10-30 15:49:05,735 module.py:666] default: "POST /task_dapau HTTP/1.1" 500 -
WARNING 2014-10-30 15:49:05,735 taskqueue_stub.py:1986] Task task4 failed to execute. The task has no remaining retries. Failing permanently after 0 retries and 0 seconds
Is this a bug? (It really looks like so)
Is there an easy workaround for it?
回答1:
As mentioned in the documentation App Engine will sometimes run a task twice. You should write your tasks to ensure that this will not be harmful.
回答2:
I just found a way to avoid the undesired retry:
taskqueue.add(
url='/blah',
queue_name='myq',
retry_options=TaskRetryOptions(task_retry_limit=0, task_age_limit=1),
countdown=1,
)
This combination of of retry_limit, age_limit and countdown is the magical incantation that does the trick.
It's still suboptimal though, so I'll leave this without a green answer until google fixes this bug.
回答3:
Check your queue.yaml file and make sure it is correctly configured.
queue:
- name: default
retry_parameters:
task_retry_limit: 0
来源:https://stackoverflow.com/questions/26657605/appengine-runs-failed-tasks-twice-even-if-task-retry-limit-0