4

If i have an Azure Function which runs on a timer trigger every 5 minutes, what happens if one run takes more than 5 minutes?

Will the next timer trigger kick off, regardless of any currently executing triggers?

Reason i ask: I need to ensure only 1 Azure Function is running at a time (yes, i know this kind of goes against the concept of functions). If one run takes < 5 minutes (most of the time it should), great - kick off next one at the next 5 minute window. If it doesn't finish, don't kick off.

I'd prefer to use Azure Functions, but in this case - should i just not bother and simply use a continuously running Azure WebJob instead?

Thanks!

RPM1984
  • 72,246
  • 58
  • 225
  • 350
  • 1
    Just a note: if you are on consumption plan, Azure Function is not allowed to run for more than 5 minutes and it will be killed at that point. – Mikhail Shilkov Feb 28 '17 at 22:48
  • @Mikhail interesting. any reference on that? – RPM1984 Feb 28 '17 at 23:12
  • Can't find a doc reference right now, but e.g. see this github issue https://github.com/Azure/Azure-Functions/issues/75 – Mikhail Shilkov Mar 01 '17 at 06:52
  • Thanks Mikhail. I'll tweak my timer schedule accordingly. – RPM1984 Mar 01 '17 at 22:39
  • This discussion is pretty old but still, here is the doc for the timeouts for the diff plans: https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale You can see the default is 5 mins for Consumption plan. – Neil Feb 08 '21 at 02:38

2 Answers2

8

As described in the TimerTrigger wiki page:

If your function execution takes longer than the timer interval, another execution won't be triggered until after the current invocation completes. The next execution is scheduled after the current execution completes.

So you should be getting the behavior you're looking for already - only a single function invocation running at any given time.

mathewc
  • 13,312
  • 2
  • 45
  • 53
0

On a timer trigger, you have the option to set an "TimeSpan" instead of an "NCRONTAB" timer.

This interval starts counting right after the execution finished and is set like this:

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "00:01:00"
    }
  ]
}

More information on MS' documentation.

Eduardo Russo
  • 4,121
  • 2
  • 22
  • 38