azure-webjobs-sdk
azure-webjobs-sdk copied to clipboard
WebJobs Shutdown signal not working
WebJobsShutdownWatcher.Token.IsCancellationRequested doesn't work.
Repro steps
Provide the steps required to reproduce the problem
- Put the following code in a stock Worker Service template in Visual Studio:
private readonly ILogger logger;
private readonly WebJobsShutdownWatcher webJobsShutdownWatcher = new ();
/// <inheritdoc/>
public Worker(ILogger<Worker> logger, IHostApplicationLifetime appLifetime)
{
this.logger = logger;
webJobsShutdownWatcher.Token.Register(() => this.logger.LogInformation("Got a shutdown from WebJobsShutdownWatcher!"));
}
public override async Task ExecuteAsync(CancellationToken cancellationToken)
{
this.logger.LogInformation("Starting ExecuteAsync");
while (!cancellationToken.IsCancellationRequested)
{
if (this.webJobsShutdownWatcher.Token.IsCancellationRequested)
{
this.logger.LogInformation("Web Job shutdown requested.");
break;
}
this.logger.LogInformation($"Doing work at {DateTime.Now}");
await Task.Delay(10000, this.appLifetime.ApplicationStopping);
}
this.logger.LogInformation("Exiting ExecuteAsync");
}
- Shut down the Web Job in the Azure portal.
Expected behavior
You expect "Web Job shutdown requested" event in the log.
Actual behavior
The Web Job stops posting messages to the log, but no indication is ever given that the WebJobsShutdownWatcher signal was received in the worker task.
Package Version: Microsoft.Azure.WebJobs 3.0.31
Deployed directly from Visual Studio to an Azure App Service using the 'Publish' function.
Hi @pragnagopa , Could you please take a look at this issue