title: Why is my Azure WebJobs "settings.job" file being ignored?
body: <p>When Azure WebJobs are stopped or restarted for whatever reason, there is a default grace period of 5 seconds before the host console process is terminated. Apparently it is possible to increase this time period by including a "settings.job" file with the WebJob when it is published to Azure, as <a href="https://github.com/mathewc/samples/tree/master/WebJobSamples/ContinuousJobGracefulShutdown" rel="nofollow noreferrer">explained here</a>. Unfortunately I cannot get this to work for my website, and the shutdown period is <em>always</em> 5 seconds, despite this being a continuous WebJob that is published to a Basic App Service that is set to "Always On".</p>
  
  <p>As per the sample code from the link, my <strong>Program.cs</strong> looks like this:</p>
  
  <pre><code>class Program
  {
      static void Main()
      {
          var host = new JobHost();
          host.RunAndBlock();
      }
  }
  </code></pre>
  
  <p>and my <strong>Functions.cs</strong> looks like this:</p>
  
  <pre><code>public class Functions
  {
      public static async Task ProcessQueueMessageAsync(
          [QueueTrigger("testq")] string message, TextWriter log,
          CancellationToken cancellationToken)
      {
          Console.WriteLine("Function started.");
          try
          {
              await Task.Delay(TimeSpan.FromMinutes(10), cancellationToken);
          }
          catch (TaskCanceledException)
          {
              Shutdown().Wait();
          }
          Console.WriteLine("Function completed succesfully.");
      }
  
      private static async Task Shutdown()
      {
          Console.WriteLine("Function has been cancelled. Performing cleanup ...");
          await Task.Delay(TimeSpan.FromSeconds(30));
          Console.WriteLine("Function was cancelled and has terminated gracefully.");
      }
  }
  </code></pre>
  
  <p>I have added a <strong>settings.job</strong> file to the project, and in its Properties in Visual Studio I have set it to "Copy always". The content of the file is as follows:</p>
  
  <pre><code>{ "stopping_wait_time": 60 }
  </code></pre>
  
  <p>The WebJob is published with the website. By using the Kudu tools and going to the debug console I can verify that the "settings.job" file is being copied across to the same location as the WebJob host executable:</p>
  
  <p><img src="https://i.stack.imgur.com/Vncz3.png" alt="Kudu screenshot"></p>
  
  <p>However, if I look at the link <code>https://xxx.scm.azurewebsites.net/api/continuouswebjobs</code> the returned JSON does not include any settings at all:</p>
  
  <pre><code>{
      "status":"Stopped",
      "detailed_status":"f9e13c - Stopped\r\n",
      "log_url":"https://...",
      "name":"WebJobTest",
      "run_command":"WebJobTest.exe",
      "url":"https://...",
      "extra_info_url":"https://...",
      "type":"continuous",
      "error":null,
      "using_sdk":true,
      "settings":{
      }
  }
  </code></pre>
  
  <p>Consequently, when I stop the WebJob from the Azure portal I end up with something like this in the logs:</p>
  
  <pre><code>[04/18/2016 12:53:12 &gt; f9e13c: SYS INFO] Run script 'WebJobTest.exe' with script host - 'WindowsScriptHost'
  [04/18/2016 12:53:12 &gt; f9e13c: SYS INFO] Status changed to Running
  [04/18/2016 12:53:13 &gt; f9e13c: INFO] Found the following functions:
  [04/18/2016 12:53:13 &gt; f9e13c: INFO] WebJobTest.Functions.ProcessQueueMessageAsync
  [04/18/2016 12:53:13 &gt; f9e13c: INFO] Job host started
  [04/18/2016 13:01:58 &gt; f9e13c: INFO] Executing: 'Functions.ProcessQueueMessageAsync' - Reason: 'New queue message detected on 'testq'.'
  [04/18/2016 13:01:58 &gt; f9e13c: INFO] Function started.
  [04/18/2016 13:02:47 &gt; f9e13c: SYS INFO] Status changed to Disabling
  [04/18/2016 13:02:53 &gt; f9e13c: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob
  [04/18/2016 13:02:53 &gt; f9e13c: SYS INFO] Status changed to Stopping
  [04/18/2016 13:02:53 &gt; f9e13c: INFO] Function has been cancelled. Performing cleanup ...
  [04/18/2016 13:02:58 &gt; f9e13c: ERR ] Thread was being aborted.
  [04/18/2016 13:02:58 &gt; f9e13c: SYS INFO] WebJob process was aborted
  [04/18/2016 13:02:58 &gt; f9e13c: SYS INFO] Status changed to Stopped
  </code></pre>
  
  <p>Note the standard 5 second gap between "Status changed to Stopping" and "Thread was being aborted".</p>
  
  <p>Why is the "settings.job" file being ignored?</p>