4

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
MLNDK
  • 85
  • 1
  • 8
  • Take a look at Azure WebJobs. It's the underline resource behind Azure Functions. I believe it supports other platforms beyond .NET Core. [Run Background tasks with WebJobs in Azure App Service](https://learn.microsoft.com/en-us/azure/app-service/webjobs-create) – Wagner DosAnjos Jan 11 '19 at 16:16
  • It does, but it seems, that Web Jobs run in the App Service Context, and also has the 230 seconds limitation. – MLNDK Jan 14 '19 at 09:58

1 Answers1

3

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>
Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
  • Thanks for your reply! I was thinking about trying bindingRedirects, but when there is no .config file, where do I put it? – MLNDK Jan 11 '19 at 23:02
  • Add a config file in – Murray Foxcroft Jan 11 '19 at 23:57
  • https://www.google.com/url?sa=t&source=web&rct=j&url=https://stackoverflow.com/questions/38093972/azure-functions-binding-redirect&ved=2ahUKEwi6xLjP9-bfAhVZDWMBHQIKBAgQFjACegQIBhAB&usg=AOvVaw2kdq8jjRMkl2SqLIXwBq3X – Murray Foxcroft Jan 12 '19 at 00:00
  • I can't find a good way to combine my backend project, containing a lot of .NET framework tools with the Azure Function 2.0 running .NET Core. It's like issue after issue. So, I guess I have to either find a way to split it into smaller bits, or find a way to run it as a background thread... – MLNDK Jan 14 '19 at 10:00
  • I don't know what your backend project is coded to do, but Azure Functions should stand alone, each one performing a specific function (single responsibility). If your functions depend on backend code, then you will either need to port that code to .net Core as well, or place the code behind a (web) service interface. – Murray Foxcroft Jan 14 '19 at 10:06
  • The reason I was considering Azure Functions in the first place was because of an App Service 230-seconds timeout on a long running task. This limitation should not be there on Azure Functions. I understand that it isn't the main purpose with Azure Functions :) – MLNDK Jan 16 '19 at 21:13