From 1eadf73d9c71bf1f3ea39a913b9ec1898558d42f Mon Sep 17 00:00:00 2001 From: Zain Kabani Date: Fri, 26 Aug 2022 14:10:50 -0400 Subject: [PATCH] Move autoreloader to own tokio task --- src/main.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 72dc7073..a0c1d7cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -154,10 +154,29 @@ async fn main() { info!("Config autoreloader: {}", config.general.autoreload); + let mut autoreload_interval = tokio::time::interval(tokio::time::Duration::from_millis(15_000)); + let autoreload_client_server_map = client_server_map.clone(); + tokio::task::spawn(async move { + loop { + autoreload_interval.tick().await; + if config.general.autoreload { + info!("Automatically reloading config"); + + match reload_config(autoreload_client_server_map.clone()).await { + Ok(changed) => { + if changed { + get_config().show() + } + } + Err(_) => (), + }; + } + } + }); + let mut term_signal = unix_signal(SignalKind::terminate()).unwrap(); let mut interrupt_signal = unix_signal(SignalKind::interrupt()).unwrap(); let mut sighup_signal = unix_signal(SignalKind::hangup()).unwrap(); - let mut autoreload_interval = tokio::time::interval(tokio::time::Duration::from_millis(15_000)); let (shutdown_tx, _) = broadcast::channel::<()>(1); let (drain_tx, mut drain_rx) = mpsc::channel::(2048); let (exit_tx, mut exit_rx) = mpsc::channel::<()>(1); @@ -182,21 +201,6 @@ async fn main() { get_config().show(); }, - _ = autoreload_interval.tick() => { - if config.general.autoreload { - info!("Automatically reloading config"); - - match reload_config(client_server_map.clone()).await { - Ok(changed) => { - if changed { - get_config().show() - } - } - Err(_) => (), - }; - } - }, - // Initiate graceful shutdown sequence on sig int _ = interrupt_signal.recv() => { info!("Got SIGINT, waiting for client connection drain now");