使用 Cloud Task、Cloud Functions 和 GAE 快速创建云任务

Rapidly creating cloud tasks using Cloud Task, Cloud Functions, and GAE

我正在使用 App Engine 触发基于列表中的项目创建多个云任务:

function_url="https://us-central1-myproject.cloudfunctions.net/some-cloud-function"

someTasks = [
{'id': 'task-1'},
{'id': 'task-2'},
{'id': 'task-3'},
...
{'id': 'task-1000'},
]

当前使用以下方法创建任务:

Parallel(backend='threading', n_jobs=100)(
        delayed(create_document_task)(function_url=function_uri, data=task) for task in someTasks 
                    )

以上代码并行创建任务并指示任务队列将负载定向到特定的云功能。

并行执行此操作是否是快速创建任务的正确方法?

- I am posting this as an answer, due to the amount of text not fitting in a comment.

似乎是前面提到的(在评论中)方法:

  • 队列(“someQueue”)。add_async(任务)

确实是个老办法。此方法在Task Queue REST API (v1), in order to asynchronously add a task or list of tasks into a task queue 内实现。

However as stated here, The App Engine Task Queue REST API (v1), was turned down as of February 20, 2018. The separate product Cloud Tasks provides a REST API that you can use to add tasks from a second generation App Engine standard environment run-time, any of the App Engine flexible environment run-times, or even from entirely outside of App Engine.

此 API 包含“add_async()”功能。更具体地说,here and here is affirmed that the feature of adding task to queues asynchronously, as the users of App Engine SDK have the option to do 不是通过 Cloud Tasks API.

提供的功能

然而,当需要添加大量的云任务时,例如数百万或数十亿,a double-injection pattern can be useful

要实现此方案,您需要创建一个新的注入器队列,其单个任务将包含用于添加您正在使用的原始队列的多个 (100) 任务的信息。在这个注入器队列的接收端将是一个服务,它会将预期的任务实际添加到您的原始队列中。虽然此服务中的任务添加是同步的并且是一对一的,但它会为您的主应用程序提供一个异步接口来批量添加任务。通过这种方式,您可以克服主应用程序中同步、1 对 1 任务添加的限制。

请注意,500/50/5 模式 将任务添加到队列是建议的方法,以避免任何 (queue/target) 过载。

由于我没有找到此实现的任何示例,我会在找到一个后立即编辑答案。

希望对您有所帮助。