Home > other >  What happens when an Azure Timer function has an execution duration that's longer shorter than
What happens when an Azure Timer function has an execution duration that's longer shorter than

Time:03-11

If an Azure function executes for say 10 minutes, but has a period of 5 minutes, does the trigger still fire at the 5 minute mark?

CodePudding user response:

The easiest way to answer this question is to test it yourself.

I created a small function that did nothing more than wait for 90 seconds after executing.

The timer is set to run every minute and therefore, the test is to see if the function still executes every minute on the minute or if it delays by the 30 seconds.

Schedule

The logs show that the answer to your question is ... NO

You can see that it's queued another execution though because as soon as it's finished, it starts again.

You'll also see the start times of each invocation is delayed by the 30 seconds additional it takes for the function to run.

This is the function ...

using System;

public static async Task Run(TimerInfo myTimer, ILogger log)
{
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

    await Task.Delay(90000);
}

Monitor Log

Logs

Invocations

Invocations

CodePudding user response:

One of the workaround I tried is:

In host.json, given the function timeout explicitly to test locally:

{
  "version": "2.0",

  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
    "functionTimeout": "00:05:00"
}

In Azure Function, Timer trigger is scheduled at every 10 minutes:

  public void Run([TimerTrigger("0 */10 * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function1 executed at: {DateTime.Now}");

enter image description here

Even Running in Azure Cloud (Consumption Mode) also, there is no timeout happened as the timer is still running every 10 minutes:

enter image description here

As mentioned in the MS Doc and an Azure blog article, the timeout comes on Azure Function request (it means your business logic should be completed before the function timeout occurs, so at every schedule you can run the same logic by using Timer Trigger).

  • Related