0

我有一个连续的 WebJob,它执行一个队列触发的函数,它偶尔会抛出 System.Threading.Tasks.TaskCanceledException。

WebJobs SDK 版本:2.1.0

堆栈跟踪:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: 
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.ProcessCreationQueueMessage ---> 
System.AggregateException : One or more errors occurred. ---> A task was canceled. at 
System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at
 System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task`1.get_Result() at
 Normandy.Portal.Reporting.Creation.WebJobs.Functions.ProcessCreationQueueMessage(String message,String& outputQueueMessage,TextWriter log) at
 D:\a\1\s\Portal\src\Normandy.Portal.Reporting.Creation.WebJobs\Functions.cs : 105 at lambda_method(Closure ,Functions ,Object[] ) at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker`2.InvokeAsync(TReflected instance,Object[] arguments) at
async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments) at 
async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance) at 
async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource) 
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) 
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) ---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException : A task was canceled.<--- End of inner exception 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) at 
async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken) 

网络作业:

        public void ProcessCreationQueueMessage([QueueTrigger("reportcreation")] string message, [Queue("reportretrieval")] out string outputQueueMessage, TextWriter log)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };

            log.WriteLine(message);

        ...

            try
            {
                var jobId = _reportingService.RequestReport(req.ReportName, searchString).Result;

                var output = new RetrieveReportDataRequest()
                {
                    CreationRequest = new ReportCreationRequest()
                    {
                        UserId = req.UserId,
                        UID = req.UID,
                        CreateDate = req.CreateDate,
                        IsMultiSchoolUser = req.IsMultiSchoolUser,
                        CentreCode = req.CentreCode,
                        ReportName = req.ReportName,
                        InputSearchParameters = req.InputSearchParameters,
                    },
                    SplunkSearchParameters = searchString,
                    SplunkJobId = jobId,
                    Created = DateTime.UtcNow,
                };

                outputQueueMessage = JsonConvert.SerializeObject(output, settings);
            }
            catch (Exception ex)
            {
                log.WriteLine(ex.Message);
                throw;
            }
        }

显然没有时间做任务。对于某些消息,这会失败一次。我错过了什么?

4

1 回答 1

0

它可能与主机设置有关 - 查看Azure Portal -> AppService配置,确保将Always On设置为On

应用服务配置

于 2019-05-01T04:45:20.993 回答