Why is my Azure WebJobs “settings.job” file being ignored?


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">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".

As per the sample code from the link, my <strong>Program.cs</strong> looks like this:

class Program { static void Main() { var host = new JobHost(); host.RunAndBlock(); } }

and my <strong>Functions.cs</strong> looks like this:

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."); } }

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:

{ "stopping_wait_time": 60 }

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:

<img alt="Kudu screenshot" class="b-lazy" data-src="https://i.stack.imgur.com/Vncz3.png" data-original="https://i.stack.imgur.com/Vncz3.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

However, if I look at the link https://xxx.scm.azurewebsites.net/api/continuouswebjobs the returned JSON does not include any settings at all:

{ "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":{ } }

Consequently, when I stop the WebJob from the Azure portal I end up with something like this in the logs:

[04/18/2016 12:53:12 > f9e13c: SYS INFO] Run script 'WebJobTest.exe' with script host - 'WindowsScriptHost' [04/18/2016 12:53:12 > f9e13c: SYS INFO] Status changed to Running [04/18/2016 12:53:13 > f9e13c: INFO] Found the following functions: [04/18/2016 12:53:13 > f9e13c: INFO] WebJobTest.Functions.ProcessQueueMessageAsync [04/18/2016 12:53:13 > f9e13c: INFO] Job host started [04/18/2016 13:01:58 > f9e13c: INFO] Executing: 'Functions.ProcessQueueMessageAsync' - Reason: 'New queue message detected on 'testq'.' [04/18/2016 13:01:58 > f9e13c: INFO] Function started. [04/18/2016 13:02:47 > f9e13c: SYS INFO] Status changed to Disabling [04/18/2016 13:02:53 > f9e13c: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob [04/18/2016 13:02:53 > f9e13c: SYS INFO] Status changed to Stopping [04/18/2016 13:02:53 > f9e13c: INFO] Function has been cancelled. Performing cleanup ... [04/18/2016 13:02:58 > f9e13c: ERR ] Thread was being aborted. [04/18/2016 13:02:58 > f9e13c: SYS INFO] WebJob process was aborted [04/18/2016 13:02:58 > f9e13c: SYS INFO] Status changed to Stopped

Note the standard 5 second gap between "Status changed to Stopping" and "Thread was being aborted".

Why is the "settings.job" file being ignored?


The problem is that your settings.job file has <strong>two</strong> sets of UTF-8 BOM, which is highly unusual and throws off the parser.

Specifically, it has the following sequence at the beginning (view using a hex editor): EF BB BF EF BB BF. Normally, the UTF-8 BOM is just EF BB BF.

What editor are you using that caused that?

In any case, once you fix that up, it should work fine.


  • What is the maximum number of simultaneous I/O operations in .net 4.5?
  • Roslyn Fix Provider Check if Fix is From Preview Window
  • Headers disappearing when using HttpSelfHostServer
  • Intermittent MongoDB Connection Issue: An attempt was made to access a socket in a way forbidden by
  • Retrieve all Types with Roslyn within a solution
  • Connecting with websockets to windows azure using MVC controller
  • C# how to write multiple lines in a text file?
  • Update ObservableCollection in list box in thread
  • Share queue with two or more stateful services within Service Fabric
  • Service vs Thread
  • Tweak output from XmlSerializer in C#
  • Xml serialization - collection attribute
  • C# Add an XML Attribute Using Object & XMLSerializer
  • Can a client cancel a Web Api request?
  • Display Current Video in Windows Phone 8 using AudioVideoCaptureDevice?
  • How to create a generic Task.ContinueWith extension method
  • Get Users in Group from Azure AD via Microsoft Graph
  • limited threads in soapUI free version
  • UITableView takes much longer to load when numberOfRows returns a large number
  • countdown bar android example
  • Replace last two characters in column
  • Authentication failed with Azure Active Directory in Windows Phone
  • How to pass nginx proxy url for socket
  • How can I replace the server in Web Component Tester
  • Clear activity stack before launching another activity
  • ThreadStatic in asynchronous ASP.NET Web API
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Record samples being played with OpenAL
  • Allowing both email and username for authentication
  • Update CALayer sublayers immediately
  • Volley JsonObjectRequest send headers in GET Request
  • Is there a amazon webstore API for customers?
  • How to get a value (ex: baseURL) in every Karate feature?
  • Perl system calls when running as another user using sudo
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Upload files with Ajax and Jquery
  • How to pass list parameters for each object using Spring MVC?
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?