How do I handle long running jobs in Azure App Service?

Viewed 4476

I am rather new to hosting in Azure. I have a .net 4.6 Web app, running in Azure as an App Service.

The solution contains some actions, that run for a long time. These get stopped after a 230 seconds timeout, which seems to be an Azure-thing.

I learned that I should place this code in an Azure Function in order to have it running as a background job. Here there should not be a timeout, as long as I don't use the Consumption plan.

I also use Azure Storage in my solution.

My problem is that if I use Azure Functions v1 (NuGet Microsoft.NET.Sdk.Functions v1.0.24), I am forced to use Newtonsoft.Json version =9.0.1 Meanwhile NuGet WindowsAzure.Storage requires Newtonsoft.Json version >=10.0.2

That breaks for me.

Then I tried out Azure Functions v2. But it only supports .Net Core, which is not an option for me in this project.

My main issue is still to find a way to be able to run these long running tasks.

One way could be to break the job into smaller parts, but in this case, I would like to be handle it in the same request.

1 Answers

Check that you do not have a timeout configured in your hosts.json.

"functionTimeout": "00:05:00"

The full configuration options for V1 and V2 are documented here.

In consumption plan, the maximum timeout is 10 minutes. In an app service plan it can be indefinite (but it makes sense to put a cap in, even if it is just 1 or 2 hours).

If you want to break up your functionality, you may find a suitable Durable Functions pattern.

On your Newtonsoft conflict, see if you can address this using a binding redirect.

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-9.9.0.0" newVersion="10.0.2.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>
Related