- 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:
2025-01-05 22:49:55 -05:00
parent f8243fe68c
commit 9f63a5fd3a
11 changed files with 37 additions and 68 deletions

View File

@@ -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"

View File

@@ -2,3 +2,4 @@ pub mod consul_registration;
pub mod service_discovery;
pub mod null_string;
pub mod redis_cache;
pub mod signal_handler;

View 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");
}
}