azure-webjobs-sdk-extensions
azure-webjobs-sdk-extensions copied to clipboard
TimerInfo has null ScheduleStatus if the interval is less than a minute
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
- Add a function to your WebJob, like
public void TestFunction([TimerTrigger("00:00:59", RunOnStartup = true, UseMonitor = true)] TimerInfo timer)
-
Run WebJob, notice that when
TestFunction()
is called,timer.ScheduleStatus
is null. -
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.
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.
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).
Any update on this?
I thought In was going crazy trying to figure out why it was null.
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.
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?
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.
And, still not fixed more than a year later.