azure-webjobs-sdk-extensions icon indicating copy to clipboard operation
azure-webjobs-sdk-extensions copied to clipboard

TimerInfo has null ScheduleStatus if the interval is less than a minute

Open cg505 opened this issue 6 years ago • 11 comments

I was debugging my TimerTrigger function with a TimeSpan string of "00:00:10", and I was getting null reference exceptions when accessing TimerInfo.ScheduleStatus. Bumped it up to "00:01:00" and everything started working.

Repro steps

  1. Add a function to your WebJob, like
public void TestFunction([TimerTrigger("00:00:59", RunOnStartup = true, UseMonitor = true)] TimerInfo timer)
  1. Run WebJob, notice that when TestFunction() is called, timer.ScheduleStatus is null.

  2. Change TimeSpan string to "00:01:00", notice issue is resolved.

Expected behavior

timer.ScheduleStatus is set.

Actual behavior

timer.ScheduleStatus is null.

Related information

  • Tried .NET 4.7 and 4.6.2
  • WebJobs and WebJobs.Extensions 2.2.0
  • I was able to reproduce the problem in a new project with no other code.

cg505 avatar Jul 16 '18 21:07 cg505

Currently by design - for schedule frequencies of less than a minute, schedule monitoring is disabled (code here).

However, I do see that you've explicitly set UserMonitor=true, but we're overriding your setting based on our 1 minute cutoff logic.

We should either throw an error here, or not override the setting if user set. I think we should do the latter - do our existing defaulting if not set explicitly by the user, but if set don't override user setting.

mathewc avatar Dec 06 '18 21:12 mathewc

I came across this same problem. ScheduleStatus was null because I was using a 30 sec timer, but as soon as I raised it to 60 seconds the problem was resolved.

This 1 minute cutoff logic feels quite arbitrary and confusing. I would expect ScheduleStatus to be always populated.

What I really need though, is the time that my function last run succesfully, not just when it was last run regardless of outcome (success or failure).

merfolk avatar Mar 21 '20 11:03 merfolk

Any update on this?

davidferro91 avatar Oct 15 '21 18:10 davidferro91

I thought In was going crazy trying to figure out why it was null.

dasiths avatar Feb 04 '22 15:02 dasiths

The documentation for timer functions explicitly mention that the default is only applied when UseMonitor is not explicitly set. https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/azure-functions/functions-bindings-timer.md

Set to true or false to indicate whether the schedule should be monitored. Schedule monitoring persists schedule occurrences to aid in ensuring the schedule is maintained correctly even when function app instances restart. If not set explicitly, the default is true for schedules that have a recurrence interval greater than or equal to 1 minute. For schedules that trigger more than once per minute, the default is false.

So either the code should be updated to match the documentation or the documentation updated to reflect that explicitly setting UseMonitor has no effect if the schedule interval is less than one minute.

MartinCa avatar Mar 02 '22 08:03 MartinCa

Any update on this? Is it likely that the code will be modified to work as described in the documentation, or will the documentation be modified along with the code?

makokui avatar Mar 13 '23 13:03 makokui

This just came up again in the alias. Moving back for Triage so we can make a change one way or another. At this point, I'm thinking we should just update the documentation to be explicit about this. Making a change to error or to no longer ignore would be a breaking behavioral change requiring a new major version.

mathewc avatar Mar 14 '23 00:03 mathewc

And, still not fixed more than a year later.

ccarmannt avatar Apr 04 '24 14:04 ccarmannt