1
votes

I have created a Cloud Task that has a retry policy with max attempts set to (for example 4).

However, we want the Task to fallback to a default solution if the Task fails for the last time.

That is, if the Task fails on the first time we just log the error and return 500. And again for the second time. And the third. Etc... but if the current TaskRetryCount is the last attempt for that queue (i.e. 4 in this example) then we will execute some fallback behaviour before returning 500 for the last time.

I can see from the Cloud Tasks HTTP Handler docs that I can get the X-CloudTasks-TaskRetryCount from the header of the request. But it doesn't seem to have a way to get the max-attempts for the queue.

Is that something that I can get hold of?

Or am I approaching this wrongly? Is there a better way of doing what I'm trying to do.

1
Why do you use Cloud Task, and not PubSub for example? Do you need some specific feature of Cloud Task? - guillaume blaquiere

1 Answers

0
votes

Assuming that the tasks are created with Cloud Tasks the queue-level retry settings apply to all tasks in the queue that were created using Cloud Tasks (as they cannot be set on individual tasks). Calling the projects.locations.queues.get method from the REST API should return the RetryConfig settings from the Queue that include the maxAttempts field that you require.

For tasks created with the App Engine SDK you should refer to this docs (although I believe that approach is deprecated and not useful for your use case).