As same code is getting executed by multiple timer triggers ( Azure Functions), how can i make sure only one code function will executed ?as we have to hit a rest api,we should allow only one function to get executed at any time
As same code is getting executed by multiple timer triggers ( Azure Functions), how can i make sure only one code function will executed ?as we have to hit a rest api,we should allow only one function to get executed at any time
Function 1 trigger will execute at 20 mnts ,another at 30 mnts ,third at 1 hr.So i should stop all the other functions at common point i.e 1 hr
Hello @SagarRallapalli-4071 , Welcome to Microsoft QnA. Thank you for the question.
I understand that you have func1, func2, func3 etc. in function App 1. So are these replica of of one another or have different implementation logic? Also do they finish execution in the stipulated time or it varies at times?
Hello @SagarRallapalli-4071 , You may consider using WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT and limit it to the minimum. However, remember this will be applied at the function app level.
You can check system.threading.semaphoreslim or system.threading.mutex and try to handle it in code.
There are couple of related discussions :
https://github.com/Azure/azure-functions-host/issues/5972
https://github.com/Azure/azure-functions-host/issues/1054
https://stackoverflow.com/questions/52836451/azure-function-app-run-single-azure-function-locally-to-debug
UPDATE
[I have checked this scenario at my end and discussed with the core product team. Sharing the suggestion based on that]
This is a unique scenario where you want to specify the limit at function level.
First, we cannot use any Host.json settings as those are host level, not function specific.
Second, Any batch setting wouldn't be applied to timers.
Third, w.r.t locking, if the app is scaled out to several instances, different timers/functions may be running on different instances, so it is not advisable to use in memory locking to synchronize.
Hence, one workaround could be redefining the schedules as per https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=csharp#ncrontab-expressions so that the schedules don't overlap.
e.g. : The first function runs on the 20 and 40 minute marks of every hour, the second on the 30 minute mark, and the last at the top of the hour.
crontab.guru
You may check durable-functions-singletons too.
Please let me know if this helps!
If yes , please "Accept the answer" and "Up-vote" so that it helps others in the community.
7 people are following this question.