[英]How do I handle long running jobs in Azure App Service?
I am rather new to hosting in Azure. 我对于在Azure中托管是相当陌生的。 I have a .net 4.6 Web app, running in Azure as an App Service.
我有一个.net 4.6 Web应用程序,作为应用程序服务在Azure中运行。
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.
它们在230秒超时后停止,这似乎是Azure事物。
I learned that I should place this code in an Azure Function in order to have it running as a background job. 我了解到,应将此代码放在Azure函数中,以使其作为后台作业运行。 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. 我还在解决方案中使用Azure存储。
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 我的问题是,如果我使用Azure Functions v1(NuGet Microsoft.NET.Sdk.Functions v1.0.24),则不得不使用Newtonsoft.Json版本= 9.0.1,同时NuGet WindowsAzure.Storage需要Newtonsoft.Json版本> = 10.0 0.2
That breaks for me. 这对我来说很糟糕。
Then I tried out Azure Functions v2. 然后,我试用了Azure Functions v2。 But it only supports .Net Core, which is not an option for me in this project.
但是它仅支持.Net Core,这不是我在该项目中的选择。
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. 一种方法是将工作分解成较小的部分,但是在这种情况下,我想在同一请求中处理它。
Check that you do not have a timeout configured in your hosts.json. 检查您的hosts.json中是否没有配置超时。
"functionTimeout": "00:05:00"
The full configuration options for V1 and V2 are documented here . V1和V2的完整配置选项在此处记录 。
In consumption plan, the maximum timeout is 10 minutes. 在消费计划中,最大超时时间为10分钟。 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).
在应用服务计划中,它可以是不确定的(但即使只是1或2个小时,也要设定上限)。
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 . 关于您的Newtonsoft冲突,请查看是否可以使用绑定重定向解决此问题。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.