Skip to content

Commit

Permalink
Add public shut_down() function (ordinals#3811)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipelincoln committed Jun 10, 2024
1 parent 4a2f072 commit 6103de9
Showing 1 changed file with 9 additions and 6 deletions.
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();
}
}
}

0 comments on commit 6103de9

Please sign in to comment.