azure-functionstimer-trigger

Azure Functions IsPastDue - when is it set to true?


I am trying to understand the IsPastDue flag.

I have written the following function in an attempt to simulate it.

[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}");
    }
}

The resulting logs are:

The flag IsPastDue is never set to true. When is it set to true?


Solution

  • The isPastDue property is true when the current function invocation is later than scheduled. For example, a function app restart might cause an invocation to be missed. Here is the official document about it.

    You can try to repro it by run the function -> stop the function -> re-run the function in visual studio locally. But this is not 100% repro. I tried it for more than 10 times, it only occurs 1 time. Here is the screenshot when isPastDue is true in my test:

    enter image description here