I have a .NET 6 application. This application contains a BackgroundService that is used to handler background jobs. These jobs are fired on a certain time based on different schedules.
I need to implement graceful shutdown when the application is stopping, because there might be some running jobs and I want to complete the jobs before stopping the application.
The app is deployed in Azure Kubernetes Service, when running this command kubectl delete pod {podname} to delete a certain pod, I am not able to handle the sigterm and write my logic to handle graceful shutdown.
I am using the IHostApplicationLifetime
and registering on the ApplicationStopping
event.
IHostApplicationLifetime _applicationLifetime;
_applicationLifetime.ApplicationStopping.Register(OnAppStopping);
In the docker file I added the below line
STOPSIGNAL SIGTERM
The OnAppStopping
is never fired on AKS.