0

I have a function app with a time trigger that should run once per night. The function looks similar to this:

    [FunctionName("XName")]
    public async Task RunAsync(
        [TimerTrigger("0 0 0 * * *", RunOnStartup = false)]
        TimerInfo myTimer)
    {
       ...
    }   

Due to some reasons, this function can be needed to be disabled for some days and then enabled again. However, even if I have set RunOnStartup to be false, the function get triggered directly even if I have enabled it at 09.00 AM.

I want to stop that, what should I do?

P.S. I don't want to change in the Cron expression because there are no specific days or specific pattern for when the function should be disabled. It is quite a random thing.

Jesse Squire
  • 6,107
  • 1
  • 27
  • 30
ibda
  • 376
  • 3
  • 15

1 Answers1

0

You might want to check the IsPastDue property of the TimerInfo object. It ...

Gets a value indicating whether this timer invocation is due to a missed schedule occurrence.

The executions you're seeing might be because the platform thinks it missed the schedule occurrence because the function was disabled and is trying to make up for the lost occurrence(s).

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.

Source: Timer trigger for Azure Functions - usage

Use the IsPastDue property to determine if the trigger is current and only execute if IsPastDue is false.

rickvdbosch
  • 14,105
  • 2
  • 40
  • 53
  • I have a number of timer based functions that run every 15 mins and looking at the logs they all have entries with `IsPastDue` set to `true` for legitimate scheduled runs if the process took longer than 30 seconds to kick off. I suspect on consumption plans the function app may take additional time to spin up in response to a scheduled timer. – Gavin Jun 28 '23 at 02:34