【问题标题】:Azure Functions IsPastDue - when is it set to true?Azure Functions IsPastDue - 何时设置为 true?
【发布时间】:2021-02-18 02:44:27
【问题描述】:

我正在尝试理解 IsPastDue 标志。

我编写了以下函数来尝试模拟它。

[FunctionName("Function1")]
public static void Run([TimerTrigger("*/30 * * * * *")]TimerInfo myTimer, ILogger log)
{
    if (myTimer.IsPastDue)
    {
        log.LogInformation($"$Custom$C# Timer trigger was delayed at: {DateTime.Now}");
    }
    else
    {
        log.LogInformation($"$Custom$C# Timer trigger function started at: {DateTime.Now}");
        Thread.Sleep(45000);
        log.LogInformation($"$Custom$C# Timer trigger function ended at: {DateTime.Now}");
    }
}

生成的日志是:

  • 2020-11-05T11:17:00.984 [信息] 正在执行“Function1”(原因=“在 2020-11-05T11:17:00.9844456+00:00 触发的计时器”,ID=0080629c-8b23-4c64-ab2b -233e389115c0)
  • 2020-11-05T11:17:00.985 [信息] $Custom$C# 定时器触发功能开始于:11/5/2020 11:17:00 AM
  • 2020-11-05T11:17:45.991 [信息] $Custom$C# 定时器触发函数结束于:11/5/2020 11:17:45 AM
  • 2020-11-05T11:17:45.991 [信息] 执行“Function1”(成功,Id=0080629c-8b23-4c64-ab2b-233e389115c0,持续时间=45007ms)
  • 2020-11-05T11:17:46.006 [信息] 正在执行“Function1”(原因=“在 2020-11-05T11:17:46.0066396+00:00 触发的计时器”,ID=94521af2-c5ef-49d9-bb05 -14e54581d3f8)
  • 2020-11-05T11:17:46.007 [信息] $Custom$C# 定时器触发功能开始于:11/5/2020 11:17:46 AM
  • 2020-11-05T11:18:31.015 [信息] $Custom$C# 定时器触发函数结束于:11/5/2020 11:18:31 AM
  • 2020-11-05T11:18:31.016 [信息] 执行“Function1”(成功,Id=94521af2-c5ef-49d9-bb05-14e54581d3f8,持续时间=45009ms)
  • 2020-11-05T11:18:31.031 [信息] 正在执行“Function1”(原因=“在 2020-11-05T11:18:31.0312837+00:00 触发的计时器”,ID=aaae053a-5d91-4d8e-bd1b -99cec8813eec)
  • 2020-11-05T11:18:31.032 [信息] $Custom$C# 定时器触发功能开始于:11/5/2020 11:18:31 AM
  • 2020-11-05T11:19:16.045 [信息] $Custom$C# 定时器触发函数结束于:11/5/2020 11:19:16 AM
  • 2020-11-05T11:19:16.046 [信息] 执行“Function1”(成功,Id=aaae053a-5d91-4d8e-bd1b-99cec8813eec,持续时间=45015ms)
  • 2020-11-05T11:19:16.062 [信息] 正在执行“Function1”(原因=“在 2020-11-05T11:19:16.0624948+00:00 触发的计时器”,ID=a00c778f-a64c-4f87-a4c3 -d523100204cb)
  • 2020-11-05T11:19:16.063 [信息] $Custom$C# 定时器触发功能开始于:11/5/2020 11:19:16 AM
  • 2020-11-05T11:20:01.073 [信息] $Custom$C# 定时器触发函数结束于:11/5/2020 11:20:01 AM
  • 2020-11-05T11:20:01.074 [信息] 执行“Function1”(成功,Id=a00c778f-a64c-4f87-a4c3-d523100204cb,持续时间=45012ms)
  • 2020-11-05T11:20:01.089 [信息] 执行“Function1”(原因='在 2020-11-05T11:20:01.0890795+00:00 触发的计时器',ID=37ad85ca-a0c0-4b7d-a39e -f9a42a5bca77)
  • 2020-11-05T11:20:01.090 [信息] $Custom$C# 定时器触发功能开始于:11/5/2020 11:20:01 AM
  • 2020-11-05T11:20:46.094 [信息] $Custom$C# 定时器触发函数结束于:11/5/2020 11:20:46 AM
  • 2020-11-05T11:20:46.095 [信息] 执行“Function1”(成功,Id=37ad85ca-a0c0-4b7d-a39e-f9a42a5bca77,持续时间=45005ms)
  • 2020-11-05T11:20:46.110 [信息] 执行“Function1”(原因='在 2020-11-05T11:20:46.1101441+00:00 触发的计时器',Id=bd3e21a2-f574-4c8b-834b -bdcf19e67d20)
  • 2020-11-05T11:20:46.110 [信息] $Custom$C# 定时器触发功能开始于:11/5/2020 11:20:46 AM

标志 IsPastDue 永远不会设置为 true。什么时候设置为true?

【问题讨论】:

    标签: azure-functions timer-trigger


    【解决方案1】:

    当当前函数调用晚于计划时,isPastDue 属性为 true。例如,函数应用 restart 可能会导致错过调用。 Here是官方文档。

    您可以尝试在本地 Visual Studio 中通过 run the function -> stop the function -> re-run the function 复制它。但这不是 100% 的再现。我试了10多次,只出现1次。这是我测试中isPastDuetrue 时的屏幕截图:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 2017-06-28
      相关资源
      最近更新 更多