Azure Functions IsPastDue - 何时设置为 true?
Azure Functions IsPastDue - when is it set to true?
我正在尝试了解 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'(原因='Timer fired at 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'(原因='Timer fired at 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'(原因='Timer fired at 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'(原因='Timer fired at 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'(原因='Timer fired at 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'(原因='Timer fired at 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。什么时候设置为真?
当当前函数调用晚于计划时,isPastDue
属性 是 true
。例如,函数应用程序 restart
可能会导致错过调用。 Here 是关于它的官方文档。
您可以尝试通过 run the function
-> stop the function
-> re-run the function
在 visual studio 本地重现。但这不是 100% 的重现。我试了10多次,只出现1次。这是我测试中 isPastDue
为 true
时的屏幕截图:
我正在尝试了解 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'(原因='Timer fired at 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'(原因='Timer fired at 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'(原因='Timer fired at 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'(原因='Timer fired at 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'(原因='Timer fired at 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'(原因='Timer fired at 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。什么时候设置为真?
当当前函数调用晚于计划时,isPastDue
属性 是 true
。例如,函数应用程序 restart
可能会导致错过调用。 Here 是关于它的官方文档。
您可以尝试通过 run the function
-> stop the function
-> re-run the function
在 visual studio 本地重现。但这不是 100% 的重现。我试了10多次,只出现1次。这是我测试中 isPastDue
为 true
时的屏幕截图: