Home > Back-end >  Prevent DeferredTask from retrying if it fails in Google App Engine
Prevent DeferredTask from retrying if it fails in Google App Engine

Time:05-25

I noticed that the com.google.appengine.api.taskqueue.DeferredTask in the Google Cloud retries if it throws an exception. Is there a way to have it not retry if it gets an error?

CodePudding user response:

From the documentation, I see this in Interface DeferredTask which I think you may be able to use:

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.

CodePudding user response:

With first gen GAE and Python, you can specify options to the deferred call like this:

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

This will prevent the task from being retried.

If you are using second gen GAE, please update your question to indicate that.

  • Related