Search code examples
c#multithreadingazureazure-functionstimer-trigger

Is it possible to execute Azure function Timer trigger with Sequential Execution?


I want to execute Azure timer trigger with the sequential execution.

Suppose i have C# Timer trigger with 5min interval. But function takes time to execute is 8min. that means before completion of first call second trigger starts another thread. how can i avoid this?


Solution

  • The defaut behavior is that at any given moment only one instance of your Azure function will be running. Quoting from the wiki -

    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.

    Here is the log output of test function that is scheduled to run every 30 seconds but takes 40 seconds itself to execute.

    C# Timer trigger function triggered at: 8/4/2017 2:21:50 PM. C# Timer trigger function executed at: 8/4/2017 2:22:30 PM. Execution count 1

    C# Timer trigger function triggered at: 8/4/2017 2:22:30 PM. C# Timer trigger function executed at: 8/4/2017 2:23:10 PM. Execution count 2

    C# Timer trigger function triggered at: 8/4/2017 2:23:10 PM. C# Timer trigger function executed at: 8/4/2017 2:23:50 PM. Execution count 3