0

我正在尝试了解 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。什么时候设置为真?

4

1 回答 1

0

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

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

在此处输入图像描述

于 2020-11-06T08:07:00.667 回答