What are the specifics of the TimerInfo class in an azure functions timer trigger?

Viewed 3118

The only documentation I can find is here but it doesn't really explain the properties on the TimerInfo class. Some questions I have

  • Does the function extension use the azure storage to save the last time the function triggered and compare that to the current execution time to see if it missed an execution and set IsPastDue to true?
  • Will IsPastDue be set to true if the function triggers a few seconds or milliseconds late or only if it missed an execution completely?
  • Is ScheduleStatus.Last the last time it triggered or is that just computed based on the cron expression?
  • What is ScheduleStatus.LastUpdated is that the last time I changed the cron expression?
  • What is Schedule.GetNextOccurrence does that return same thing as ScheduleStatus.Next if I pass DateTime.Now
2 Answers

After doing some testing and reading the source code this is my summary of what it does. I'll explain what it does when UseMonitor is set to true.

When the function host starts it checks the azure storage for the last time the trigger executed. If it has never executed it waits for the next scheduled occurrence based on your cron expression. If it has executed before it compares the last time it executed to the current time to see if it missed any executions. If it did miss any it immediately executes your function and passes IsPastDue as true. Then it continues to execute on the regular schedule.

ScheduleStatus.Last:

  • The first time running it will be set to default(DateTime).
  • If its past due it will be the actual last time your function executed
  • Otherwise it is the last time it executed rounded to the nearest scheduled execution

ScheduleStatus.Next:

  • The next scheduled execution time which is usually approximately the current time unless the execution is past due in which case it would be in the past.

ScheduleStatus.LastUpdated:

  • As for as I can tell this is the same as ScheduleStatus.Last except it will be default(DateTime) if its the first execution

Does the function extension use the azure storage to save the last time the function triggered and compare that to the current execution time to see if it missed an execution and set IsPastDue to true?

The default value of the IsPastDue is false.

public TimerInfo(TimerSchedule schedule, ScheduleStatus status, bool isPastDue = false)
{
    Schedule = schedule;
    ScheduleStatus = status;
    IsPastDue = isPastDue;
}

Will IsPastDue be set to true if the function triggers a few seconds or milliseconds late or only if it missed an execution completely?

If the schedule is past due, this value will be true.

Is ScheduleStatus.Last the last time it triggered or is that just computed based on the cron expression?

The value is obtained from DateTime.Now(The time you execute last time.), not computed based on the cron expression.

What is ScheduleStatus.LastUpdated is that the last time I changed the cron expression?

This value is obtained from the as same value as ScheduleStatus.Last:

            ScheduleStatus = new ScheduleStatus
            {
                Last = adjustedInvocationTime,
                Next = _schedule.GetNextOccurrence(adjustedInvocationTime),
                LastUpdated = adjustedInvocationTime
            };

What is Schedule.GetNextOccurrence does that return same thing as ScheduleStatus.Next if I pass DateTime.Now

Because ScheduleStatus is instantiated by the value provided by Schedule.GetNextOccurrence.

The source code:

https://github.com/Azure/azure-webjobs-sdk-extensions/blob/a3a5a49a64f3592c1eb7c1296086dc83c2011e96/src/WebJobs.Extensions/Extensions/Timers/TimerInfo.cs

https://github.com/Azure/azure-webjobs-sdk-extensions/blob/a3a5a49a64f3592c1eb7c1296086dc83c2011e96/src/WebJobs.Extensions/Extensions/Timers/Listener/TimerListener.cs

Please have a look.

Related