Add more flexibility when fetching production value
This commit is contained in:
parent
7b9db9c7c3
commit
57a9c03308
@ -71,7 +71,11 @@ pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
|
||||
let response = match curl {
|
||||
false => reqwest::get(url).await?.json::<FroniusResponse>().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());
|
||||
|
@ -25,7 +25,14 @@ impl EnergyActor {
|
||||
pub async fn new() -> anyhow::Result<Self> {
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user