gpt4 book ai didi

定时器触发器运行两次的 Azure 函数

转载 作者:行者123 更新时间:2023-12-05 09:13:40 27 4
gpt4 key购买 nike

我遇到过类似的情况 Azure Function timer is running twice and when I log onto the Azure portal但到目前为止,我的解决方案还没有为我工作。

我的函数(用 Node 编写)在计时器上运行(每 15 分钟一次)。在 Application Insights 和 Azure 门户监视器日志中,我每 15 分钟就会看到一次调用,正如预期的那样(可能是由于采样)。但是,输出发生了两次(我正在将记录写入 Cosmos 集合)。当我观看函数的实时日志时(在门户中,导航到函数代码并从屏幕底部拉出日志),我可以看到它运行了两次,非常接近。下面是示例日志。间隔重叠,所以我不认为这是 CRON 问题(但我不是 CRON 专家)。

我确实考虑过 runOnStartup。我不确定这是否默认为 false,因此我将其设置为 false 并重新启动。重启后同样问题。 (我仍然对此表示怀疑,因为一分钟计时器上的类似功能应用程序按预期运行)。

我还尝试过从门户手动运行该功能。当我这样做时,它只运行一次。

提供 Azure 函数 github wiki 上请求的信息:

  1. 我正在使用消费计划
  2. 不确定需要多少信息 - 我们使用 Azure DevOps 管道和 Kudu。
  3. v2(预览版)运行时
  4. 未设置 WEBSITE_TIME_ZONE
  5. 我的 CRON 表达式:0 */15 * * * * 我对其含义的期望:函数应每 15 分钟运行一次。
  6. 不适用
  7. 从接近的位置开始提供两个 -

    • 调用 ID:4e142315-60e3-420d-b71a-9990683ba5aa
    • 调用日期时间:2019-04-18T17:45:00.0044464+00:00
    • 地区:美国东部

    • 调用 ID:4c6f4e7a-1e9d-4278-b3c6-0a2b5310199c

    • 调用日期时间:2019-04-18T17:45:00.0131739+00:00
    • 地区:美国东部
<小时/>

显示两个重叠调用的示例日志记录(为简单起见,对实际日志文本进行了轻微编辑):

2019-04-18T17:45:00.004 [Information] Executing 'Functions.unassignDriverPermits' (Reason='Timer fired at 2019-04-18T17:45:00.0044464+00:00', Id=4e142315-60e3-420d-b71a-9990683ba5aa)

2019-04-18T17:45:00.013 [Information] Executing 'Functions.unassignDriverPermits' (Reason='Timer fired at 2019-04-18T17:45:00.0131739+00:00', Id=4c6f4e7a-1e9d-4278-b3c6-0a2b5310199c)

2019-04-18T17:45:33.577 [Information] Log a thing about something

2019-04-18T17:45:33.577 [Information] Log a thing about id 0

2019-04-18T17:45:33.586 [Information] Executed 'Functions.unassignDriverPermits' (Succeeded, Id=4e142315-60e3-420d-b71a-9990683ba5aa)

2019-04-18T17:45:33.281 [Information] Log a thing about something

2019-04-18T17:45:33.282 [Information] Log a thing about id 0

2019-04-18T17:45:33.294 [Information] Executed 'Functions.unassignDriverPermits' (Succeeded, Id=4c6f4e7a-1e9d-4278-b3c6-0a2b5310199c)

最佳答案

我的函数曾经在每天 12:00 运行时遇到过类似的问题。 RunOnStartup 设置为 true。该函数按照消耗计划运行,并且通过仅每天运行,该函数会在触发时解除分配并重新启动(在冷启动中)。也许这就是双重调用的原因:一次用于触发器,一次因为它已启动)。通过将 RunOnStartup 设置为 false 可以修复此问题。

确保 RunOnStartup 设置为 false。

关于定时器触发器运行两次的 Azure 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55751490/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com