Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "trick" Azure Function into running longer than 10 minutes

Azure Functions have a time limit of 10 minutes. Suppose I have a long-running task such as downloading a file that takes 1 hr to download.

[FunctionName("PerformDownload")]
[return: Queue("download-path-queue")]
public static async Task<string> RunAsync([QueueTrigger("download-url-queue")] string url, TraceWriter log)
{
   string downloadPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString);
   log.Info($"Downloading file at url {url} to {downloadPath} ...");
   using (var client = new WebClient())
   {
       await client.DownloadFileAsync(new Uri(url), myLocalFilePath);
   }
   log.Info("Finished!");   
}

Is there any hacky way to make something like this start and then resume in another function before the time limit expires? Or is there a better way altogether to integrate some long task like this into a workflow that uses Azure Functions?

(On a slightly related note, is plain Azure Web Jobs obsolete? I can't find it under Resources.)

like image 999
user7127000 Avatar asked Jul 14 '18 21:07

user7127000


People also ask

How do I increase the timeout on my azure function?

json. In a recent update, the Azure Functions team at Microsoft has added a configuration option that enables an Azure Functions App to have the timeout increased. To implement this, the functionTimeout property within the host. json file for an Azure Function App can be set to a timespan duration of 10 minutes.

How long can an azure function run for?

How Long Can Azure Functions Run? For any Azure Functions, a single Function execution has a maximum of 5 minutes by default to execute. If the Function is running longer than the maximum timeout, then the Azure Functions runtime can end the process at any point after the maximum timeout has been reached.

What is default timeout for Azure function app?

Function app timeout duration Regardless of the function app timeout setting, 230 seconds is the maximum amount of time that an HTTP triggered function can take to respond to a request. This is because of the default idle timeout of Azure Load Balancer.


2 Answers

Adding for others who might come across this post: Workflows composed of several Azure Functions can be created in code using the Durable Functions extension, which can be used to create orchestration functions that schedule async tasks, shut down, and are reawakened when said async work is complete.

They're not a direct solution for long-running tasks that require an open TCP port, such as downloading a file, (for that, a function running on an App Service Plan has no execution time limit), but it can be used to integrate such tasks into a larger workflow.

like image 102
Katy Shimizu Avatar answered Oct 01 '22 20:10

Katy Shimizu


Is there any hacky way to make something like this start and then resume in another function before the time limit expires?

If you are on a Consumption Plan you have no control over how long your Function App runs, and so it would not be reliable to use background threads that continue running after your Function entry point completes.

On an App Service plan you're running on VMs you pay for, so you can configure your Function App to run continuously. Also AFAIK you don't have to have a Function timeout on an App Service Plan, so your main Function entry point can run for as long as you want.

Or is there a better way altogether to integrate some long task like this into a workflow that uses Azure Functions?

Yes. Use Azure Data Factory to copy data into Blob Storage, and then process it. The Data Factory pipeline can call Functions both before and after the copy activity.

like image 45
David Browne - Microsoft Avatar answered Oct 01 '22 20:10

David Browne - Microsoft