阻止 DeferredTask 在 Google App Engine 中失败时重试

Prevent DeferredTask from retrying if it fails in Google App Engine

我注意到 Google Cloud 中的 com.google.appengine.api.taskqueue.DeferredTask 在抛出异常时会重试。有没有办法让它在出错时不重试?

注意:使用JAVA

来自 documentation, I see this in Interface DeferredTask,我认为您可以使用:

Normal return from this method is considered success and will not retry unless DeferredTaskContext.markForRetry() is called. Exceptions thrown from this method will indicate a failure and will be processed as a retry attempt unless DeferredTaskContext.setDoNotRetry(boolean) was set to true.

使用第一代 GAE 和 Python,您可以像这样为延迟调用指定选项:

retry = taskqueue.TaskRetryOptions(task_retry_limit=0)
deferred.defer(..., _retry_options=retry)

这将阻止重试任务。

如果您使用的是第二代 GAE,请更新您的问题以表明这一点。