C# 连续运行的webjob在20分钟后被中止

C# 连续运行的webjob在20分钟后被中止,c#,azure-webjobs,azure-webjobssdk,webjob,C#,Azure Webjobs,Azure Webjobssdk,Webjob,我正在Premium tier中的web应用(应用程序服务)下运行web作业。它调用RESTAPI端点,这需要很长时间才能返回响应。web作业将在20分钟后中止,但根据文档,web作业可以在后台运行长时间运行的任务。这似乎不像预期的那样有效 是否为web作业功能指定了最大超时 守则: public async Task<HttpResponseMessage> GetAsync(Uri requestUrl) { _httpClient.DefaultRequestHeade

我正在Premium tier中的web应用(应用程序服务)下运行web作业。它调用RESTAPI端点,这需要很长时间才能返回响应。web作业将在20分钟后中止,但根据文档,web作业可以在后台运行长时间运行的任务。这似乎不像预期的那样有效

是否为web作业功能指定了最大超时

守则:

public async Task<HttpResponseMessage> GetAsync(Uri requestUrl)
{
    _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GetAadAuthentication().AccessToken);
    var httpResponse = await _httpClient.GetAsync(requestUrl);
    if (!httpResponse.IsSuccessStatusCode)
    {
        ProcessFailedRequest(httpResponse);
    }

    return httpResponse;
}
公共异步任务GetAsync(Uri请求URL) { _httpClient.DefaultRequestHeaders.Authorization=新的AuthenticationHeaderValue(“承载者”,GetAadAuthentication().AccessToken); var httpResponse=await\u httpClient.GetAsync(requestUrl); 如果(!httpResponse.IsSuccessStatusCode) { ProcessFailedRequest(httpResponse); } 返回httpResponse; } 异常日志:

[05/26/2017 21:28:01 > 6e349c: ERR ] Unhandled Exception: System.Threading.Tasks.TaskCanceledException: A task was canceled.
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at Util.testWebClient.<GetAsync>d__12.MoveNext() in d:\test\Util\testWebClient.cs:line 99
[05/26/2017 21:28:01 > 6e349c: ERR ] --- End of stack trace from previous location where exception was thrown ---
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at Util.testClient.<GetForecastResultAsync>d__7.MoveNext() in d:\test\Util\testClient.cs:line 135
[05/26/2017 21:28:01 > 6e349c: ERR ] --- End of stack trace from previous location where exception was thrown ---
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at AutoAggregation.Functions.<>c__DisplayClass18_0.<ProcessResultDownloadMessage>b__0(Object workItem) in d:\test\AutoAggregation\Functions.cs:line 198
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading.ThreadPoolWorkQueue.Dispatch()
[05/26/2017 21:28:01 > 6e349c: ERR ]    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
[05/26/2017 21:28:01>6e349c:ERR]未处理的异常:System.Threading.Tasks.TaskCanceledException:任务已取消。
[05/26/2017 21:28:01>6e349c:ERR]at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务)
[05/26/2017 21:28:01>6e349c:ERR]at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务)
[05/26/2017 21:28:01>6e349c:ERR]在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()上
[05/26/2017 21:28:01>6e349c:ERR]在d:\test\Util\testWebClient.cs中的Util.testWebClient.d_u12.MoveNext()处:第99行
[05/26/2017 21:28:01>6e349c:ERR]——来自引发异常的前一个位置的堆栈结束跟踪---
[05/26/2017 21:28:01>6e349c:ERR]在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()时
[05/26/2017 21:28:01>6e349c:ERR]at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务)
[05/26/2017 21:28:01>6e349c:ERR]at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务)
[05/26/2017 21:28:01>6e349c:ERR]在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()上
[05/26/2017 21:28:01>6e349c:ERR]在d:\test\Util\testClient.cs:第135行中的Util.testClient.d_u7.MoveNext()处
[05/26/2017 21:28:01>6e349c:ERR]——来自引发异常的前一个位置的堆栈结束跟踪---
[05/26/2017 21:28:01>6e349c:ERR]在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()时
[05/26/2017 21:28:01>6e349c:ERR]at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务)
[05/26/2017 21:28:01>6e349c:ERR]at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务)
[05/26/2017 21:28:01>6e349c:ERR]在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()上
[05/26/2017 21:28:01>6e349c:ERR]在自动聚合.Functions.c__显示d:\test\AutoAggregation\Functions.cs:第198行中的Class18_0.b_u0(对象工作项)
[05/26/2017 21:28:01>6e349c:ERR]位于System.Threading.QueueUserWorkItemCallback.WaitCallback_上下文(对象状态)
[05/26/2017 21:28:01>6e349c:ERR]位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext、ContextCallback回调、对象状态、布尔值保留SyncCTX)
[05/26/2017 21:28:01>6e349c:ERR]在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext、ContextCallback回调、对象状态、布尔保留同步CTX)
[05/26/2017 21:28:01>6e349c:ERR]位于System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()处
[05/26/2017 21:28:01>6e349c:ERR]位于System.Threading.ThreadPoolWorkQueue.Dispatch()处
[05/26/2017 21:28:01>6e349c:ERR]at System.Threading.\u ThreadPoolWaitCallback.PerformWaitCallback()

您可能正在使用免费托管计划层?这个()博客精确地描述了相同的问题和解决方法。对于专业用途,我建议增加托管计划


TLDR:免费计划下的应用程序池最多可以运行20分钟。

我将HttpClient的超时时间增加为:

_httpClient = new HttpClient();
_httpClient.Timeout=Timeout.InfiniteTimeSpan;
之前它被设置为

_httpClient.Timeout=new TimeSpan(0, 20, 0);

我正在高级层运行azure网站/webjob。此20分钟超时是否也适用于高级web作业?在更高的计划中,您可以启用“始终打开”,从而消除此限制