title: azure webjob stopped with Unhandled Exception: 503 Server Unavailable
body: <p>i have a web job with a QueueTrigger. i wrap the process function with try&amp;catch but it seems like azure queue is throwing an unhandled exception that i cant catch in my code.
  how can i automatically restart the webjob?
  how can i add retry policy to the webjob sdk?</p>
  
  <p>this is the exception i see in the webjob log (which shows that the error occurs in the webjob sdk timer) :</p>
  
  <pre><code>04/18/2015 11:10:52 &gt; 2d2f34: ERR ] 
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ] Unhandled Exception: Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (503) Server Unavailable. ---&gt; System.Net.WebException: The remote server returned an error: (503) Server Unavailable.
  [04/18/2015 11:10:52 &gt; 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 &gt; 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.&lt;ExistsImpl&gt;b__1d(RESTCommand`1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    --- End of inner exception stack trace ---
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.EndExists(IAsyncResult asyncResult)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.&lt;&gt;c__DisplayClass1`1.&lt;CreateCallback&gt;b__0(IAsyncResult ar)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ] --- End of stack trace from previous location where exception was thrown ---
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at Microsoft.Azure.WebJobs.Host.Queues.Listeners.QueueListener.&lt;ExecuteAsync&gt;d__4.MoveNext()
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ] --- End of stack trace from previous location where exception was thrown ---
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at Microsoft.Azure.WebJobs.Host.Timers.TaskSeriesTimer.&lt;RunAsync&gt;d__d.MoveNext()
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ] --- End of stack trace from previous location where exception was thrown ---
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at Microsoft.Azure.WebJobs.Host.Timers.BackgroundExceptionDispatcher.&lt;&gt;c__DisplayClass1.&lt;Throw&gt;b__0()
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  [04/18/2015 11:10:52 &gt; 2d2f34: ERR ]    at System.Threading.ThreadHelper.ThreadStart()
  [04/18/2015 11:10:52 &gt; 2d2f34: SYS INFO] Status changed to Failed
  [04/18/2015 11:10:52 &gt; 2d2f34: SYS ERR ] Job failed due to exit code -532462766
  </code></pre>
  
  <p>this is my code:</p>
  
  <pre><code>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);              
      }
  }
  </code></pre>