0
votes

We have Azure Functions executing stored procedure every 2 seconds. Most of the time 90% of the time the stored procedure will finish in less than 1 second. But if the json is big and have lots of values some times it runs for more than 2 seconds. I don't want the Azure function to start until the one its running is completed.

    [FunctionName("OrderOIHSync")]
    public static async Task RunSingle([TimerTrigger("*/2 * * * * *")]TimerInfo myTimer, ILogger log)

Is this the right approach or how I can control so in exception cases the azure function don't trigger. Based on documentation timer trigger says singleton but I seen cases where it's triggering and causing some data issues.

Any suggestions appreciated.

1
I would decouple this and maybe send a queue message to trigger the stored procedure or have a data layer keeping state of your triggers. - lopezbertoni
docs.microsoft.com/en-us/answers/questions/45561/… Can some one verify if this is the case I don't have to worry even if the stored procedure runs more than 2 seconds - Nathan
What kind of stored procedure you executing? If your original blob is stored in azure storage, I would like to suggest you use blob trigger function other than timer trigger. - Doris Lv
Regarding the singleton lock it's a yes. When you start up a function it creates a file in blob storage that acts as a lock. That is, if you're running this in Azure and you execute the same azure function locally pointing to the same storage aacount, only one of them will run. - lopezbertoni
Thanks Lopezbertoni and Doris LV After carefully checking it's running singleton only. - Nathan

1 Answers

0
votes

A timer trigger function won't trigger again if there is an outstanding invocation still running. There is an internal Timer to keep track of that. After your function completes execution when the function is invoked the timer starts again. So, at any given moment only one instance of your Azure function will be running.

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.

Check here

Now you can make use of the property “IsPastDue” and control the executions accordingly. The IsPastDue flag is passed to your azure function to indicate if the timer was overdue or not

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.

quoted from here

{
"Schedule":{
},
"ScheduleStatus": {
    "Last":"2016-10-04T10:15:00+00:00",
    "LastUpdated":"2016-10-04T10:16:00+00:00",
    "Next":"2016-10-04T10:20:00+00:00"
},
"IsPastDue":false

}