feat(Core): gracefully shutdown router/scheduler if Redis is unavailable (#891)

Co-authored-by: prajjwal kumar <prajjwal.kumar@prajjwalkumar-DWKH9NPY4R.local>
Co-authored-by: Nishant Joshi <nishant.joshi@juspay.in>
Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
Prajjwal Kumar
2023-04-24 13:08:00 +05:30
committed by GitHub
parent 85c7629061
commit 13185999d5
21 changed files with 166 additions and 74 deletions

View File

@ -2,20 +2,21 @@
use futures::StreamExt;
use router_env::logger;
pub use tokio::sync::oneshot;
use tokio::sync::mpsc;
///
/// This functions is meant to run in parallel to the application.
/// It will send a signal to the receiver when a SIGTERM or SIGINT is received
///
pub async fn signal_handler(mut sig: signal_hook_tokio::Signals, sender: oneshot::Sender<()>) {
pub async fn signal_handler(mut sig: signal_hook_tokio::Signals, sender: mpsc::Sender<()>) {
if let Some(signal) = sig.next().await {
logger::info!(
"Received signal: {:?}",
signal_hook::low_level::signal_name(signal)
);
match signal {
signal_hook::consts::SIGTERM | signal_hook::consts::SIGINT => match sender.send(()) {
signal_hook::consts::SIGTERM | signal_hook::consts::SIGINT => match sender.try_send(())
{
Ok(_) => {
logger::info!("Request for force shutdown received")
}