awl
awl

Reputation: 1559

azure function max execution time

I would like to have a function called on a timer (every X minutes) but I want to ensure that only one instance of this function is running at a time. The work that is happening in the function shouldn't take long, but if for some reason it takes longer than the scheduled timer (X minutes) I don't want another instance to start and the processes to step on each other.

The simplest way that I can think of would be to set a maximum execution time on the function to also be X minutes. I would want to know how to accomplish this in both the App Service and Consumption plans, even if they are different approaches. I also want to be able to set this on an individual function level.

This type of feature is normally built-in to a FaaS environment, but I am having the hardest time google-binging it. Is this possible in the function.json? Or also are there different ways to make sure that this runs only once?

(PS. I know I could this in my own code by wrapping the work in a thread with a timeout. But I was hoping for something more idiomatic.)

Upvotes: 1

Views: 6380

Answers (3)

Bart Czernicki
Bart Czernicki

Reputation: 3683

There is a new Azure Functions plan called Premium (in public preview as of May 2019) that allows for unlimited execution duration: https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale

It will probably end up the goto plan for most Enterprise scenarios.

Upvotes: 2

Matt Mason
Matt Mason

Reputation: 2726

Timer functions already have this behavior - they take out a blob lease from the AzureWebJobsStorage storage account to ensure that only one instance is executing the timer function. Also, the timer will not execute while a previous scheduled execution is in flight.

Another roll-your-own possibility is to handle this with storage queues and visibility timeout - when the queue has finished processing, push a new queue message with visibility timeout to match the desired schedule.


I want to mention that the functionTimeout host.json property will add a timeout to all of your functions, but has the side effect that your function will fail with a timeout error and that function instance will restart, so I wouldn't rely on it in this case.

Upvotes: 2

Alexey Rodionov
Alexey Rodionov

Reputation: 1446

You can specify 'functionTimeout' property in host.json https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json

// Value indicating the timeout duration for all functions.
// In Dynamic SKUs, the valid range is from 1 second to 10 minutes and the default value is 5 minutes.
// In Paid SKUs there is no limit and the default value is null (indicating no timeut).
       "functionTimeout": "00:05:00"

Upvotes: 2

Related Questions