简体   繁体   English

Cloud Scheduler 在调度期间多次调用 Cloud Function

[英]Cloud Scheduler invokes Cloud Function more than once during schedule

I currently have a Cloud Function that is executing some asynchronous code.我目前有一个 Cloud Function 正在执行一些异步代码。 It is making a Get request to an Endpoint to retrieve some data and then it storing that data into a Cloud Storage.它向 Endpoint 发出 Get 请求以检索一些数据,然后将该数据存储到 Cloud Storage 中。 I have set up the Cloud Function to be triggered using Cloud Scheduler via HTTP. When I use the test option that Cloud Function has, everything works fine, but when I set up Cloud Scheduler to invoke the Cloud Function, it gets invoked more than once.我已经将 Cloud Function 设置为通过 HTTP 使用 Cloud Scheduler 触发。当我使用 Cloud Function 具有的测试选项时,一切正常,但是当我设置 Cloud Scheduler 以调用 Cloud Function 时,它被调用了不止一次. I was able to tell by looking at the logs and it showing multiple execution id's and print statements I have in place.我可以通过查看日志来判断,它显示了多个execution id's和我已准备好的打印语句。 Does anyone know why the Cloud Scheduler is invoking more than once?有谁知道为什么 Cloud Scheduler 调用不止一次? I have the Max Retry Attempts set to 0. There is a portion in my code where I use asyncio's create_task and sleep in order to put make sure the tasks get put into the event loop to slow down the number of requests and I was wondering if this is causing Cloud Scheduler to do something unexpected?我将Max Retry Attempts设置为 0。我的代码中有一部分使用asyncio's create_tasksleep以确保将任务放入事件循环以减慢请求数量,我想知道是否这会导致 Cloud Scheduler 执行意外操作吗?

async with aiohttp.ClientSession(headers=headers) as session:
    tasks = []

    for i in range(1, total_pages + 1):
        tasks.append(asyncio.create_task(self.get_tasks(session=session,page=i)))
        await asyncio.sleep(delay_per_request)

For my particular case, when natively testing (using the test option cloud function has built-in) my Cloud Function was performing as expected.对于我的特殊情况,当进行本地测试时(使用内置的测试选项云 function),我的云 Function 按预期运行。 However, when I set up Cloud Scheduler to trigger the Cloud Function via a HTTP, it unexpectedly ran more than once.但是,当我设置 Cloud Scheduler 以通过 HTTP 触发 Cloud Function 时,它意外地运行了不止一次。 As @EdoAkse mentioned in original thread here my event with Cloud Scheduler was running more than once.正如@EdoAkse 在此处的原始线程中提到的,我使用 Cloud Scheduler 的事件运行了不止一次。 My solution was to set up Pub/Sub topic that the Cloud Function subscribes to and that topic will trigger that Cloud Function. The Cloud Scheduler would then invoke that Pub/Sub Trigger.我的解决方案是设置 Cloud Function 订阅的 Pub/Sub 主题,该主题将触发 Cloud Function。然后 Cloud Scheduler 将调用该 Pub/Sub 触发器。 It is essentially how Google describes it in their docs .它本质上是谷歌在他们的文档中描述它的方式。

  • Cloud Scheduler -> Pub/Sub Trigger -> Cloud Function云调度程序 -> 发布/订阅触发器 -> 云 Function

Observed a behavior where cloud functions were being called twice by Cloud Scheduler.观察到 Cloud Scheduler 两次调用云函数的行为。 Apparently, despite them being located/designated as eu-west1, a duplicate entry in schedule was present for each scheduled function located in us-central1.显然,尽管它们位于/指定为 eu-west1,但对于位于 us-central1 的每个预定 function,在时间表中存在重复条目。 Removing the duplicated calls in us-central1 resolved my issue.删除 us-central1 中的重复调用解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM