加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – azure webjob因未处理的异常而停止:503服务器不可用

发布时间:2020-12-15 22:13:14 所属栏目:百科 来源:网络整理
导读:我有一个带有QueueTrigger的Web作业.我用try catch包装了进程函数,但似乎azure队列抛出了一个未处理的异常,我无法在我的代码中捕获. 我怎样才能自动重启webjob? 如何将重试策略添加到webjob sdk? 这是我在webjob日志中看到的异常(显示webjob sdk计时器中发
我有一个带有QueueTrigger的Web作业.我用try& catch包装了进程函数,但似乎azure队列抛出了一个未处理的异常,我无法在我的代码中捕获.
我怎样才能自动重启webjob?
如何将重试策略添加到webjob sdk?

这是我在webjob日志中看到的异常(显示webjob sdk计时器中发生错误):

04/18/2015 11:10:52 > 2d2f34: ERR ] 
[04/18/2015 11:10:52 > 2d2f34: ERR ] Unhandled Exception: Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (503) Server Unavailable. ---> System.Net.WebException: The remote server returned an error: (503) Server Unavailable.
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException[T](HttpStatusCode expectedStatusCode,HttpStatusCode actualStatusCode,T retVal,StorageCommandBase`1 cmd,Exception ex)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.<ExistsImpl>b__1d(RESTCommand`1 cmd,HttpWebResponse resp,Exception ex,OperationContext ctx)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    --- End of inner exception stack trace ---
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.EndExists(IAsyncResult asyncResult)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass1`1.<CreateCallback>b__0(IAsyncResult ar)
[04/18/2015 11:10:52 > 2d2f34: ERR ] --- End of stack trace from previous location where exception was thrown ---
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.Azure.WebJobs.Host.Queues.Listeners.QueueListener.<ExecuteAsync>d__4.MoveNext()
[04/18/2015 11:10:52 > 2d2f34: ERR ] --- End of stack trace from previous location where exception was thrown ---
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.Azure.WebJobs.Host.Timers.TaskSeriesTimer.<RunAsync>d__d.MoveNext()
[04/18/2015 11:10:52 > 2d2f34: ERR ] --- End of stack trace from previous location where exception was thrown ---
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at Microsoft.Azure.WebJobs.Host.Timers.BackgroundExceptionDispatcher.<>c__DisplayClass1.<Throw>b__0()
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,Object state)
[04/18/2015 11:10:52 > 2d2f34: ERR ]    at System.Threading.ThreadHelper.ThreadStart()
[04/18/2015 11:10:52 > 2d2f34: SYS INFO] Status changed to Failed
[04/18/2015 11:10:52 > 2d2f34: SYS ERR ] Job failed due to exit code -532462766

这是我的代码:

public static async Task  ManualTrigger([QueueTrigger(ConstantVars.TargetjobQueue)] TargetingJob job,TextWriter log)
{
    try
    {
        AddTextWriterToAppender(log);

        _logger.DebugFormat("Starting job");
        _logger.DebugFormat("Job details: {0}",job);

        await ProcessJob(job).ConfigureAwait(false);

        _logger.Debug("Finished job");

        RemoveTextWriterFromAppender();
    }
    catch (Exception e)
    {
        _logger.Error(string.Format("Unhandled exception was caught in ManualTrigger.n jobParams={0}",job.ToString()),e);              
    }
}

解决方法

如您所知,存储异常发生在您的工作职能之外,因此您无法捕获它.但是,webjobs SDK将处理失败并根据其自身的内部随机指数退避策略自动重试失败的调用.您可以在启动时控制设置JobHostConfiguration.Queues.MaxDequeueCount的重试次数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读