问题描述
我正在尝试了解IsPastDue标志。
我编写了以下函数以对其进行仿真。
[FunctionName("Function1")]
public static void Run([TimerTrigger("*/30 * * * * *")]TimerInfo myTimer,ILogger log)
{
if (myTimer.IsPastDue)
{
log.Log@R_985_4045@ion($"$Custom$C# Timer trigger was delayed at: {DateTime.Now}");
}
else
{
log.Log@R_985_4045@ion($"$Custom$C# Timer trigger function started at: {DateTime.Now}");
Thread.Sleep(45000);
log.Log@R_985_4045@ion($"$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#计时器触发功能在以下时间结束:2020/11/5 11:20:01 AM
- 2020-11-05T11:20:01.074 [信息]执行了'Function1'(成功,Id = a00c778f-a64c-4f87-a4c3-d523100204cb,持续时间= 45012ms)
- 2020-11-05T11:20:01.089 [信息]执行“功能1”(原因=“计时器在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#计时器触发功能在以下时间结束:2020年11月5日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?
解决方法
当前函数调用晚于计划时间时,isPastDue
属性为true
。例如,功能应用restart
可能会导致调用丢失。 Here是关于它的正式文件。
您可以尝试通过run the function
-> stop the function
-> re-run the function
在本地Visual Studio中对其进行复制。但这不是100%复制。我尝试了10次以上,它只出现1次。这是测试中isPastDue
为true
时的屏幕截图: