I was wondering if anybody knows what happens if you have a Cron setting on an Azure Function to run every 5 minutes if its task takes more than 5 minutes to execute. Does it back up? Or should I implement a locking feature that would prevent something, say in a loop, from handling data already being processed by a prior call?
HTTPClient is thread safe, as many others are, so you dont need to worry about it, but please check the documentation thoroughly for other classes.
The timer trigger uses a storage lock to ensure that there is only one timer instance when a function app scales out to multiple instances. If two function apps share the same identifying configuration and each uses a timer trigger, only one timer runs.
Navigate to your function app in the Azure portal, select App Keys, and then the _master key. In the Edit key section, copy the key value to your clipboard, and then select OK. After copying the _master key, select Code + Test, and then select Logs.
A trigger defines how a function is invoked and a function must have exactly one trigger.
Azure function with timer trigger will only run one job at a time. If a job takes longer then next one is delayed.
Quoting from 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.
That is true even if you scale out.
https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer#scale-out
You may want to ensure that your function does not time out on you. See https://buildazure.com/2017/08/17/azure-functions-extend-execution-timeout-past-5-minutes/ on how to configure function timeout.
If a timer trigger occurs again before the previous run has completed, it will start a second parallel execution.
Ref: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference#parallel-execution
When multiple triggering events occur faster than a single-threaded function runtime can process them, the runtime may invoke the function multiple times in parallel.
Something else to note is that even using the new WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT
settings, you cannot prevent multiple executions on the same instance.
Each instance of the function app, whether the app runs on the Consumption hosting plan or a regular App Service hosting plan, might process concurrent function invocations in parallel using multiple threads.
The best advice is to either reduce the duration it takes to execute, through optimisation or changing the approach to the problem. Perhaps splitting the task down and triggering it in a different way may help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With