-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait for background workers to finish current jobs before quitting #860
Wait for background workers to finish current jobs before quitting #860
Conversation
@jacovdbergh logic have changed just a bit, can you take a look at the conflict and see what makes sense? |
…vdbergh/loco into wait-for-background-workers
@jondot merged in master and fixed conflict. Also fixed clippy and other CI checks, so good to merge from my side if you're happy. |
Thanks for this fix. Note that there may be already a bug there, say we have a It might be worth to explicitly have back the case for Otherwise when the cases are unified, it kind of mingles with also having to keep in mind the So anything you can do to make the 3 cases distinct might be helpful (1) server only (2) worker+server, inprocess worker (3) worker only. it's also worth remembering that the modes for the worker make or may not make sense in one of the 3 cases (BackgroundQueue, Async, Foreground). For example, Async does not make sense in a stand-alone process. |
The reason I changed it to always spawn the queue into a tokio worker thread is because we need to somehow listen (in another thread) for the shutdown signal. After the shutdown signal, we join on the queue worker handle, which lets it finish any currently running tasks, and then gracefully quit. So in short, we always need a worker and handle for the queue worker now, and then the shutdown signal is either awaited in the Router or explicitly by the same code that spawned the queue worker. Let me know how you think the above can be achieved differently? |
Got it now! thanks for the clarification |
…vdbergh/loco into wait-for-background-workers
I've refactored the flow for readability, let me know if that's better? |
oh wow fantastic! thanks for this, super clear! ❤️ |
…oco-rs#860) * wait for background workers
This PR utilises the cancellation token provided by sidekiq-rs to wait for currently processing background jobs before exiting.
When the token is canceled, no new jobs will be picked up by the queue, only currently running jobs will be completed.
Waiting can be interrupted by sending another ctrl-c if the user wishes to force quit the app.
The PR aims to do this in a generic way so that a similar approach can be implemented for the postgres queue implementation as well in future.
Feedback on the println! added is welcomed, to fit in with the rest of Loco's way/style of outputting info.