Skip to content
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

Create public shutdown function #3811

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,13 @@ pub fn parse_ord_server_args(args: &str) -> (Settings, subcommand::server::Serve
}
}

fn gracefully_shutdown_indexer() {
pub fn shut_down() {
SHUTTING_DOWN.store(true, atomic::Ordering::Relaxed);
}

fn gracefully_shut_down_indexer() {
if let Some(indexer) = INDEXER.lock().unwrap().take() {
// We explicitly set this to true to notify the thread to not take on new work
SHUTTING_DOWN.store(true, atomic::Ordering::Relaxed);
shut_down();
log::info!("Waiting for index thread to finish...");
if indexer.join().is_err() {
log::warn!("Index thread panicked; join failed");
Expand All @@ -246,7 +249,7 @@ pub fn main() {
.iter()
.for_each(|handle| handle.graceful_shutdown(Some(Duration::from_millis(100))));

gracefully_shutdown_indexer();
gracefully_shut_down_indexer();
})
.expect("Error setting <CTRL-C> handler");

Expand All @@ -268,15 +271,15 @@ pub fn main() {
eprintln!("{}", err.backtrace());
}

gracefully_shutdown_indexer();
gracefully_shut_down_indexer();

process::exit(1);
}
Ok(output) => {
if let Some(output) = output {
output.print(format.unwrap_or_default());
}
gracefully_shutdown_indexer();
gracefully_shut_down_indexer();
}
}
}
Loading