From 23430cc3cbb04f31b1a846ecb5295f0d9054c440 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Mon, 1 Dec 2025 11:03:41 -0800 Subject: [PATCH] KL-6 Remove monitoring_interval panic --- bin/core/src/config.rs | 14 ++++++++++++++ bin/core/src/monitor/mod.rs | 15 +++++---------- bin/core/src/monitor/swarm.rs | 6 +++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/bin/core/src/config.rs b/bin/core/src/config.rs index 1791ed785..752a5df8e 100644 --- a/bin/core/src/config.rs +++ b/bin/core/src/config.rs @@ -123,6 +123,20 @@ pub fn cors_layer() -> CorsLayer { cors } +pub fn monitoring_interval() -> async_timing_util::Timelength { + static MONITORING_INTERVAL: OnceLock< + async_timing_util::Timelength, + > = OnceLock::new(); + *MONITORING_INTERVAL.get_or_init(|| { + core_config().monitoring_interval.try_into().unwrap_or_else( + |_| { + error!("Invalid 'monitoring_interval', using default 15-sec"); + async_timing_util::Timelength::FifteenSeconds + }, + ) + }) +} + pub fn core_config() -> &'static CoreConfig { static CORE_CONFIG: OnceLock = OnceLock::new(); CORE_CONFIG.get_or_init(|| { diff --git a/bin/core/src/monitor/mod.rs b/bin/core/src/monitor/mod.rs index fcb700660..6d8cf4b49 100644 --- a/bin/core/src/monitor/mod.rs +++ b/bin/core/src/monitor/mod.rs @@ -21,7 +21,7 @@ use serror::Serror; use tokio::sync::Mutex; use crate::{ - config::core_config, + config::monitoring_interval, helpers::periphery_client, monitor::{alert::check_alerts, record::record_server_stats}, state::{ @@ -46,19 +46,14 @@ pub use swarm::update_cache_for_swarm; const ADDITIONAL_MS: u128 = 500; pub fn spawn_monitoring_loops() { - let interval = core_config() - .monitoring_interval - .try_into() - .expect("Invalid monitoring interval"); - spawn_server_monitoring_loop(interval); - swarm::spawn_swarm_monitoring_loop(interval); + spawn_server_monitoring_loop(); + swarm::spawn_swarm_monitoring_loop(); } -fn spawn_server_monitoring_loop( - interval: async_timing_util::Timelength, -) { +fn spawn_server_monitoring_loop() { tokio::spawn(async move { refresh_server_cache(komodo_timestamp()).await; + let interval = monitoring_interval(); loop { let ts = (wait_until_timelength(interval, ADDITIONAL_MS).await - ADDITIONAL_MS) as i64; diff --git a/bin/core/src/monitor/swarm.rs b/bin/core/src/monitor/swarm.rs index 8b04c1927..326ef7635 100644 --- a/bin/core/src/monitor/swarm.rs +++ b/bin/core/src/monitor/swarm.rs @@ -20,17 +20,17 @@ use periphery_client::api::swarm::{ use tokio::sync::Mutex; use crate::{ + config::monitoring_interval, helpers::swarm::swarm_request_custom_timeout, state::{CachedSwarmStatus, db_client, swarm_status_cache}, }; const ADDITIONAL_MS: u128 = 1000; -pub fn spawn_swarm_monitoring_loop( - interval: async_timing_util::Timelength, -) { +pub fn spawn_swarm_monitoring_loop() { tokio::spawn(async move { refresh_swarm_cache(komodo_timestamp()).await; + let interval = monitoring_interval(); loop { let ts = (wait_until_timelength(interval, ADDITIONAL_MS).await - ADDITIONAL_MS) as i64;