3

I'm trying to create a Cloud Tasks queue that never retries if an HTTP task fails.

According to the documentation, maxAttempts should be what I'm looking for:

Number of attempts per task.

Cloud Tasks will attempt the task maxAttempts times (that is, if the first attempt fails, then there will be maxAttempts - 1 retries). Must be >= -1.

So, if maxAttempts is 1, there should be 0 retries.

But, for example, if I run

gcloud tasks queues create test-queue --max-attempts=1 --log-sampling-ratio=1.0

then use the following Python code to create an HTTP task:

from google.cloud import tasks_v2beta3
from google.protobuf import timestamp_pb2
client = tasks_v2beta3.CloudTasksClient()
project = 'project_id' # replace by real project ID
queue = 'test-queue'
location = 'us-central1'
url = 'https://example.com/task_handler' # replace by some endpoint that return 5xx status code
parent = client.queue_path(project, location, queue)
task = {
        'http_request': {  # Specify the type of request.
            'http_method': 'POST',
            'url': url  # The full url path that the task will be sent to.
        }
}
response = client.create_task(parent, task)
print('Created task {}'.format(response.name))

In the Stackdriver logs for the queue (which I can see because I used --log-sampling-ratio=1.0 when creating the queue), the task is apparently retried once: there is one dispatch attempt, followed by a dispatch response with status UNAVAILABLE, followed by another dispatch attempt, which is finally followed by the last dispatch response (also indicating UNAVAILABLE).

Is there any way to retry 0 times?

Note

About maxAttempts, the documentation also says:

This field has the same meaning as task_retry_limit in queue.yaml/xml.

However, when I go to the description for task_retry_limit, it says:

The number of retries. For example, if 0 is specified and the task fails, the task is not retried at all. If 1 is specified and the task fails, the task is retried once. If this parameter is unspecified, the task is retried indefinitely. If task_retry_limit is specified with task_age_limit, the task is retried until both limits are reached.

This seems to be inconsistent with the description of maxAttempts, as it indicates that the task would be retried once if the parameter is 1.

I've experimented with setting maxAttempts to 0, but that seems to make it assume a default value of 100.

Thank you in advance.

favq
  • 739
  • 1
  • 11
  • 25
  • 1
    I put in a bug to clear up the difference between max_attempts and task_retry_limit. I'm curious though, do you know what response code your handler is returning? – Averi Kitsch Sep 26 '19 at 17:22
  • @AveriKitsch - Thank you. I've tested with a dummy handler that always returns response code 500. But I've first noticed it happening with a "real" handler that had a temporary error and returned 500 in the first dispatch, then the task was subsequently retried 1 time and succeeded (i.e., returning 200). – favq Sep 26 '19 at 19:36
  • 1
    I apologize for the slow response. This is a bug. At the moment I am unable to give an estimate on when the fix will be released. – Averi Kitsch Oct 07 '19 at 22:14
  • @AveriKitsch No problem, thank you for the reply. – favq Oct 07 '19 at 22:54

1 Answers1

2

As @averi-kitsch mentioned, this is currently an internal issue which our Cloud Tasks engineer team is working on right now, sadly we don't have any ETA yet.

You can follow the progress of this issue with this Public Issue Tracker, click on the "star" to subscribe to it and receive future updates.

As a work around, if you don't want the task to retry after it fails, set "task_retry_limit=0" directly on the queue.yaml.

Example :

queue:
- name: my-queue1
 rate: 1/s
 retry_parameters:
   task_retry_limit: 0
Mayeru
  • 1,044
  • 7
  • 12
  • Thank you - so this means that, if I want no retries, I should switch to managing queues by using a queue.yaml file for now, rather than using the Cloud Tasks API via commands such as "gcloud tasks queues create". – favq Oct 11 '19 at 00:12
  • That is correct. Keep an eye on the issue tracker to know whenever the issue with the "gcloud tasks queues create" command is fixed and live. – Mayeru Oct 11 '19 at 10:36