Skip to content

Commit

Permalink
Add graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 24, 2024
1 parent 7705db3 commit fca8694
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ std = [
"tokio/macros",
"tokio/sync",
"tokio/parking_lot",
"tokio/signal",
]
shuttle = [
"shuttle-axum",
Expand All @@ -38,13 +39,13 @@ optional = true

# Feature `shuttle` depend on it.
[dependencies.shuttle-axum]
version = "0.35"
version = "0.37"
default-features = false
features = ["axum-0-7"]
optional = true

# Feature `shuttle` depend on it.
[dependencies.shuttle-runtime]
version = "0.36"
version = "0.37"
default-features = false
optional = true
15 changes: 14 additions & 1 deletion coordinator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ async fn main() {

let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
debug!("listening on {}", listener.local_addr().unwrap());
axum::serve(listener, route()).await.unwrap();
axum::serve(listener, route())
.with_graceful_shutdown(shutdown_signal())
.await
.unwrap();
}

#[cfg(feature = "shuttle")]
Expand All @@ -35,3 +38,13 @@ async fn main() -> shuttle_axum::ShuttleAxum {
.init();
Ok(route().into())
}

#[cfg(feature = "std")]
async fn shutdown_signal() {
use tracing::info;

tokio::signal::ctrl_c()
.await
.expect("Expect shutdown signal handler");
info!("Shutdown...");
}

0 comments on commit fca8694

Please sign in to comment.