KL-6 Remove monitoring_interval panic

This commit is contained in:
mbecker20
2025-12-01 11:03:41 -08:00
parent d44be15c14
commit 23430cc3cb
3 changed files with 22 additions and 13 deletions

View File

@@ -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<CoreConfig> = OnceLock::new();
CORE_CONFIG.get_or_init(|| {

View File

@@ -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;

View File

@@ -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;