From a1e4ca35cd7dc06956bb6c25f64bbe951a4af902 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 8 Mar 2023 18:49:56 -0500 Subject: [PATCH] configurable health check duration --- crates/service/web/storyteller_web/src/main.rs | 11 +++++++++-- .../db_health_checker_thread.rs | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/service/web/storyteller_web/src/main.rs b/crates/service/web/storyteller_web/src/main.rs index 3f8dbf11b7..2b29dde081 100644 --- a/crates/service/web/storyteller_web/src/main.rs +++ b/crates/service/web/storyteller_web/src/main.rs @@ -293,6 +293,9 @@ async fn main() -> AnyhowResult<()> { let twitch_secrets = TwitchSecrets::from_env()?; + let health_check_interval = easyenv::get_env_duration_seconds_or_default( + "HEALTH_CHECK_INTERVAL_SECS", Duration::from_secs(3)); + let static_api_token_set = read_static_api_tokens(); // Background jobs. @@ -308,8 +311,12 @@ async fn main() -> AnyhowResult<()> { info!("Spawning DB health checker thread."); - tokio_runtime.spawn(async { - db_health_checker_thread(health_check_status2, mysql_pool3).await; + tokio_runtime.spawn(async move { + db_health_checker_thread( + health_check_status2, + mysql_pool3, + health_check_interval, + ).await; }); info!("Spawning IP ban polling thread."); diff --git a/crates/service/web/storyteller_web/src/threads/db_health_checker_thread/db_health_checker_thread.rs b/crates/service/web/storyteller_web/src/threads/db_health_checker_thread/db_health_checker_thread.rs index 7698d3a4c5..c49f264602 100644 --- a/crates/service/web/storyteller_web/src/threads/db_health_checker_thread/db_health_checker_thread.rs +++ b/crates/service/web/storyteller_web/src/threads/db_health_checker_thread/db_health_checker_thread.rs @@ -12,6 +12,7 @@ use std::time::Duration; pub async fn db_health_checker_thread( health_check_status: HealthCheckStatus, mysql_pool: MySqlPool, + check_duration: Duration, ) { loop { debug!("Checking DB health..."); @@ -32,7 +33,7 @@ pub async fn db_health_checker_thread( } } - thread::sleep(Duration::from_millis(3_000)); + thread::sleep(check_duration); } warn!("Should never happen: Health Checker Exits");