I am trying to implement graceful shutdown for a continuous Azure web job, provided the required job settings:
{
"stopping_wait_time": 3600,
"is_singleton": true
}
I have registered the callback:
static void Main(string[] args)
{
var cancellationToken = new WebJobsShutdownWatcher().Token;
cancellationToken.Register(() =>
{
Console.WriteLine("Shutdown Started...");
Thread.Sleep(5000);
Console.WriteLine("Waited 5 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 10 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 15 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 20 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 25 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 30 seconds!" + DateTime.Now.ToString());
});
JobHost host = new JobHost();
MethodInfo methodInfo = typeof(Functions).GetMethod("GracefulShutdown");
host.CallAsync(methodInfo); //a long running method
host.RunAndBlock();
}
But on stopping the web job, I can never get the last line of the callback executed:
Console.WriteLine("Waited 30 seconds!" + DateTime.Now.ToString()
Any thoughts?