Skip to content

Commit

Permalink
feat: limit graceful shutdown interval and add force exit
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Sep 27, 2023
1 parent 5331734 commit f46ac26
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions examples/ping-pong/src/main.rs
@@ -1,7 +1,10 @@
use chrono::Utc;
// Load environment variables from .env file
use dotenv::dotenv;
use std::sync::atomic::{AtomicBool, Ordering};
use std::{
process,
sync::atomic::{AtomicBool, Ordering},
};
use tokio::signal;

// Import Arc and Mutex for thread-safe sharing of data across threads
Expand Down Expand Up @@ -63,15 +66,19 @@ async fn main() {

tokio::select! {
_ = ctrl_c => {
println!("Ctrl+C received! Shutting down...");
info!("Ctrl+C received! Shutting down...");
}
_ = sigterm => {
println!("SIGTERM received! Shutting down...");
info!("SIGTERM received! Shutting down...");
}
}
// Set running boolean to false
debug!("Finish the current running processes...");
listen_running.store(false, Ordering::SeqCst)
listen_running.store(false, Ordering::SeqCst);

sleep(Duration::from_secs(5));
debug!("Allowed 5 seconds for graceful shutdown, force exit");
process::exit(1);
});

// Instantiates the configuration struct based on provided environment variables or CLI args
Expand Down

0 comments on commit f46ac26

Please sign in to comment.