Graceful shutdown of jobs #2182
Unanswered
gitterdonewell
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Have you tried to configure Quartz to do the interrupt for you? services.AddQuartz(options => .... options.InterruptJobsOnShutdown = true); |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm having an issue with the graceful shutdown of jobs. Most likely I'm not doing this right and would appreciate your help.
I have a
.NET 6.0
console app withQuartz.Extensions.Hosting (3.7.0)
. I have a long running job that does something in a loop and potentially runs for like 3 hours at a time. Inside the loop, I monitor for thecancellationToken.IsCancellationRequested
value and if it is true, I log and audit the work up to that point and break the loop to exit the job. Example below:DI
MyJob.cs
JobSchedule.cs
Program.cs
When I debug the console app in VS 2022 and press CTR+C, the ApplicationStopping event is called which in turn calls the ShutdownQuartz() private method above. As soon as the
cancellationTokenSource.Cancel()
line is hit, immediately the console app exits and VS stops debugging.So cancelling the token source seems to shutdown the scheduler along with the jobs immediately without waiting. If I have the break point inside the loop in the job, The
context.CancellationToken.IsCancellationRequested
is never set totrue
aftercancellationTokenSrouce.Cance()
is called. At some point like 5 seconds later, the app crashes taking down the job with it. Seems like 5 seconds is the default .NET host shutdown limit. A singleCancellationToken
fromProgram.cs
is used across the entire app so cancelling it in theShutdownQuartz()
should set it to true in the entire app but theIsCancellationRequested
property inside the job is never set to true. I'm not sure if my setup is right for the graceful shutdown of the jobs. I would appreciate your help. ThanksBeta Was this translation helpful? Give feedback.
All reactions