2

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

根据文档, maxAttempts 应该是我正在寻找的:

每个任务的尝试次数。

Cloud Tasks 将尝试任务 maxAttempts 次(即,如果第一次尝试失败,则将有 maxAttempts - 1 次重试)。必须 >= -1。

因此,如果 maxAttempts 为 1,则应该有 0 次重试。

但是,例如,如果我运行

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

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

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 的调度响应,然后是另一次调度尝试,这最后是最后一个调度响应(也表示不可用)。

有没有办法重试0次?

笔记

关于 maxAttempts,文档还说:

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

但是,当我转到task_retry_limit 的描述时,它说:

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

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

我已经尝试将 maxAttempts 设置为 0,但这似乎使它假定默认值为 100。

先感谢您。

4

1 回答 1

2

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

您可以使用此公共问题跟踪器跟踪此问题的进度,单击“星号”以订阅它并接收未来的更新。

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

例子 :

queue:
- name: my-queue1
 rate: 1/s
 retry_parameters:
   task_retry_limit: 0
于 2019-10-08T07:41:21.743 回答