- 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

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