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

Cloud Scheduler invokes Cloud Function more than once during schedule

我目前有一个 Cloud Functions 正在执行一些异步代码。它向 Endpoint 发出 Get 请求以检索一些数据,然后将该数据存储到 Cloud Storage 中。我已将 Cloud Function 设置为通过 HTTP 使用 Cloud Scheduler 触发。当我使用 Cloud Function 的测试选项时,一切正常,但是当我设置 Cloud Scheduler 来调用 Cloud Function 时,它被调用了不止一次。我可以通过查看日志来判断,它显示了多个 execution id's 和我已经准备好的打印语句。有谁知道为什么 Cloud Scheduler 调用不止一次?我将 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)

对于我的特殊情况,在本机测试时(使用测试选项云函数 built-in)我的云函数按预期执行。但是,当我设置 Cloud Scheduler 以通过 HTTP 触发 Cloud Function 时,它意外 运行 不止一次。正如@EdoAkse 在原始线程 here my event with Cloud Scheduler was running more than once. 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. It is essentially how Google describes it in their docs.

中提到的
  • 云调度程序 -> Pub/Sub 触发器 -> 云函数