diff --git a/central_backend/src/energy/consumption.rs b/central_backend/src/energy/consumption.rs index f9ae070..d24b6ca 100644 --- a/central_backend/src/energy/consumption.rs +++ b/central_backend/src/energy/consumption.rs @@ -71,7 +71,11 @@ pub async fn get_curr_consumption() -> anyhow::Result { let response = match curl { false => reqwest::get(url).await?.json::().await?, true => { - let res = std::process::Command::new("curl").arg(url).output()?; + let res = std::process::Command::new("curl") + .arg("--connect-timeout") + .arg("1.5") + .arg(url) + .output()?; if !res.status.success() { return Err(ConsumptionError::CurlReqFailed.into()); diff --git a/central_backend/src/energy/energy_actor.rs b/central_backend/src/energy/energy_actor.rs index 0f58c71..b586ecd 100644 --- a/central_backend/src/energy/energy_actor.rs +++ b/central_backend/src/energy/energy_actor.rs @@ -25,7 +25,14 @@ impl EnergyActor { pub async fn new() -> anyhow::Result { let consumption_cache_size = AppConfig::get().refresh_interval / AppConfig::get().energy_fetch_interval; - let curr_consumption = consumption::get_curr_consumption().await?; + let curr_consumption = match consumption::get_curr_consumption().await { + Ok(v) => v, + Err(e) => { + log::warn!("Failed to fetch consumption, using default value! {e}"); + constants::FALLBACK_PRODUCTION_VALUE + } + }; + log::info!("Initial consumption value: {curr_consumption}"); let mut consumption_cache = ConsumptionCache::new(consumption_cache_size as usize); consumption_cache.add_value(curr_consumption);