删除 Google Cloud Tasks 时可以使用通配符吗?

Can I use wildcards when deleting Google Cloud Tasks?

我对 Google Cloud Tasks 很陌生。

我想知道,在deleting a task时有没有办法使用通配符?例如,如果我使用以下 ID 命名结构在队列中可能有 3 个任务...

  1. id-123-任务-1
  2. id-123-任务-2
  3. id-123-task-3

我可以简单地删除 id-123-task-* 来删除所有 3 个,还是每次都必须删除所有 3 个特定 ID?我想我正在尝试限制所需的 API 调用次数以删除与 'id-123'.

相关的所有内容

Can I use wildcards when deleting Google Cloud Tasks?

截至今天,Google Cloud Tasks 不支持通配符。我无法确认您是否可以像您提到的那样传递 Google Cloud Task 的 ID id-123-task-* 将删除所有任务。

尽管如此,如果您正在为特定目的创建任务,则可以为此类任务创建一个单独的队列。

您不仅会在组织任务方面获胜,而且当您想删除所有任务时,您只需要清除所有任务指定队列 仅进行 1 API 次调用。

Here you could see how to purge all tasks from the specified queue, and also how to delete tasks and queues.

此外,我附上了 API documentation 以防您需要有关在 Cloud Tasks 中清除队列的更多信息。

如所述here,请考虑如果您清除队列中的所有任务:

Do not create new tasks immediately after purging a queue. Wait at least a second. Tasks created in close temporal proximity to a purge call will also be purged.

此外,如果您正在使用 命名任务 ,如所述 here:

You can assign your own name to a task by using the name parameter. However, this introduces significant performance overhead, resulting in increased latencies and potentially increased error rates associated with named tasks. These costs can be magnified significantly if tasks are named sequentially, such as with timestamps.

因此,如果您使用命名任务,文档建议为任务名称使用分布均匀的前缀,例如内容的哈希。

如果您想限制API次调用的数量,我认为这是最好的解决方案。

希望对您有所帮助。