Google Cloud Tasks HTTP trigger - how to disable retry

偶尔善良 提交于 2020-08-06 05:09:03

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/58117520/google-cloud-tasks-http-trigger-how-to-disable-retry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!