- update: moved signal handler into utils crate to make it easier to update
- fix: windows compile issue due to exposed unix signal
This commit is contained in:
@@ -10,7 +10,7 @@ tracing = "0.1"
|
||||
rand = "0.9.0-beta.1"
|
||||
uuid = { version = "1.11.0", features = ["v4"] }
|
||||
warp = "0.3.7"
|
||||
tokio = "1.41.1"
|
||||
tokio = { version = "1.41.1", features = ["full"] }
|
||||
bincode = { version = "2.0.0-rc.3", features = ["derive", "serde"] }
|
||||
redis = "0.27.5"
|
||||
deadpool-redis = "0.18.0"
|
||||
|
||||
@@ -2,3 +2,4 @@ pub mod consul_registration;
|
||||
pub mod service_discovery;
|
||||
pub mod null_string;
|
||||
pub mod redis_cache;
|
||||
pub mod signal_handler;
|
||||
|
||||
27
utils/src/signal_handler.rs
Normal file
27
utils/src/signal_handler.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use tokio::{select, signal};
|
||||
use tracing::info;
|
||||
|
||||
pub async fn wait_for_signal() {
|
||||
select! {
|
||||
_ = signal::ctrl_c() => {
|
||||
info!("Received SIGINT (Ctrl+C), shutting down...");
|
||||
},
|
||||
_ = terminate_signal() => {
|
||||
info!("Received termination signal, shutting down...");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn terminate_signal() {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
let mut sigterm = signal(SignalKind::terminate()).expect("Failed to set up SIGTERM handler");
|
||||
sigterm.recv().await;
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
signal::ctrl_break().await.expect("Failed to set up CTRL_BREAK handler");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user