如何使用 Google Cloud Scheduler 安排对 GraphQL 端点的调用

How to schedule a call to a GraphQL endpoint using Google Cloud Scheduler

我在 Google Cloud 运行 的实例中有一个 GraphQL 应用程序 运行ning 运行。

我想使 运行 实例保持温暖。因此,我正在尝试配置 Google Cloud Scheduler 调用 ping 端点。

调用端点的 curl 命令下方:

curl 'https://myapi-xxxxxx-xx.x.run.app/' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'Authorization: bearer 123456' --data-binary '{"query":"\n{\n  ping\n}\n\n  ","variables":{}}' --compressed

如何创建新的计划来对端点进行类似的调用?

您可能对以 HTTP 为目标的 Cloud Scheduler 感兴趣。 documentation 显示创建 cron 作业所需的所有步骤:

  • 指定作业将联系的终结点的完全限定 URL。

  • 指定 HTTP 方法。默认为 POST.

  • 可选,指定要发送到目标的数据。 This data is sent in the body of the request as bytes when either the POST or PUT HTTP method is selected.

  • 要创建需要身份验证的 HTTP 目标作业,请参阅 Using Authentication with HTTP Targets

仅当您需要验证对云 运行 服务的请求时才需要最后一点。