Reputation: 1
I have an Azure function that processes the top N items from a backlog. It occasionally takes longer to process N items than is allowed by the configured functionTimeout
setting and so, to avoid being cancelled by the runtime, the function reads the functionTimeout
value from host.json when it is invoked and finishes processing early when approaching cancellation time.
This approach works okay but it has some flaws:-
functionTimeout
setting to a value higher than the maximum allowed by the service plan then I believe the host.json setting would be ignored and so my function wouldn't know its maximum allowed duration and the 'finish early' logic would fail.functionTimeout
setting (either because we're relying on service plan defaults or because the value has been specified as an app setting instead) then the function likewise won't know its maximum allowed durationWhat I'd really like my function to be able to do is query the runtime host to ask how much time is allowed because if that's possible then I can probably use the same generic approach for other functions. Note that I'm not trying to change the allowed duration, I'm trying to discover what it is at runtime.
I hoped that if I allowed an IConfiguration object to be injected into my function then I might see whatever functionTimeout got resolved to after all appropriate configurations were processed by the runtime but I didn't see any relevant-looking setting when I examined the results of _configuration.GetChildren()
in the debugger.
IEnumerable<IConfigurationSection> children = _configuration.GetChildren();
var timeyChildren = children.Where(_ => _.Key.Contains("time", StringComparison.CurrentCultureIgnoreCase)).ToList();
Is there any other place I might be able to discover at runtime from the host itself, how long the function is going to be allowed to run?
Upvotes: 0
Views: 71
Reputation: 3649
Is there any other place I might be able to discover at runtime from the host itself, how long the function is going to be allowed to run?
The Azure Functions runtime doesn't provide a built-in API to fetch the effective timeout setting at runtime. The timeout is determined based on:
functionTimeout
in the host.json
file.Please refer this MS DOC for better understanding about functionTimeout
.
We can define functionTimeout in the host.json
as shown below.
"functionTimeout": "00:10:00"
The timeout settings in the host.json
file cannot exceed the limits of the service plan.
The maximum time limit for a Function App on the Consumption plan is 10 minutes, while Premium and Dedicated plans allow execution time up to 60 minutes.
You can use custom timeout logic to estimate the remaining execution time by using the FunctionContext.GetInvocationMetadata()
method.
If you are using the Consumption plan, it's better to upgrade it to Premium or Dedicated plan.
Reference : How can I increase the timeout for Azure Consumption plan for more than 10 mins - Microsoft Q&A
Upvotes: 0