Google Cloud Tasks HTTP触发器-如何禁用重试 [英] Google Cloud Tasks HTTP trigger - how to disable retry

查看:116
本文介绍了Google Cloud Tasks HTTP触发器-如何禁用重试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Cloud Tasks队列,该任务在HTTP任务失败时永远不会重试.

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

根据文档, maxAttempts应该是我要找的东西:

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

每个任务的尝试次数.

Number of attempts per task.

Cloud Tasks将尝试任务maxAttempts次(即,如果 第一次尝试失败,然后将出现maxAttempts-1次重试).必须 是> = -1.

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.

因此,如果maxAttempts为1,则应进行0次重试.

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

然后使用以下Python代码创建HTTP任务:

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))

在队列的Stackdriver日志中(可以看到,因为我在创建队列时使用了--log-sampling-ratio=1.0),该任务显然被重试了一次:有一次调度尝试,然后是状态为UNAVAILABLE的调度响应,然后是进行另一次调度尝试,最后是最后一个调度响应(也指示不可用").

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).

有什么办法可以重试0次?

Is there any way to retry 0 times?

注意

关于maxAttempts,文档还显示:

About maxAttempts, the documentation also says:

此字段的含义与queue.yaml/xml中的task_retry_limit相同.

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

但是,当我转到 task_retry_limit的说明,它说:

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

重试次数.例如,如果指定了0且任务 失败,则根本不重试该任务.如果指定1并且任务 失败,任务将重试一次.如果未指定此参数,则 任务将无限期重试.如果将task_retry_limit指定为 task_age_limit,重试任务,直到达到两个限制.

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.

这似乎与maxAttempts的描述不一致,因为它表明如果参数为1,则将重试一次任务.

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.

我尝试将maxAttempts设置为0,但这似乎使其假定默认值为100.

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

谢谢.

推荐答案

正如@ averi-kitsch所提到的,这是内部问题,我们的Cloud Tasks工程师团队目前正在处理此问题,可惜我们没有任何ETA

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.

作为一种变通方法,如果您不希望任务失败后重试,请直接在queue.yaml上设置" task_retry_limit = 0 ".

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.

示例:

queue:
- name: my-queue1
 rate: 1/s
 retry_parameters:
   task_retry_limit: 0

这篇关于Google Cloud Tasks HTTP触发器-如何禁用重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆