Skip to content

Commit

Permalink
Better duration logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
orium committed Dec 29, 2023
1 parent 0c39a08 commit c5b3758
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ toml = "0.8.8"
serde_derive = "1.0.193"
simplelog = "0.12.1"
log = { version = "0.4.20", features = [] }
humantime = "2.1.0"

[features]
fatal-warnings = []
Expand Down
20 changes: 9 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ async fn log_temperature(

if age > Duration::from_secs(30 * 60) {
warn!(
"Ignoring temperature {:.02} °C of fermenter \"{}\" because the temperature is too old ({:?}).",
"Ignoring temperature {:.02} °C of fermenter \"{}\" because the temperature is too old ({}).",
temp_record.temperature,
fermenter.name,
age,
humantime::format_duration(Duration::from_secs(age.whole_seconds() as u64)),
);
return;
}
Expand Down Expand Up @@ -192,21 +192,19 @@ async fn main_loop(config: Config) -> ! {
}

for ferm in ferms {
let temp_record = match grainfather.get_fermenter_temperature(ferm.id).await {
Ok(Some(temp)) => temp,
match grainfather.get_fermenter_temperature(ferm.id).await {
Ok(Some(temp_record)) => {
info!("Fermenter \"{}\": {:.02} °C", ferm.name, temp_record.temperature);

log_temperature(&brewfather, &mut last_logged, &ferm, temp_record).await;
}
Ok(None) => {
info!("No recent temperature record of fermenter \"{}\".", ferm.name);
continue;
}
Err(err) => {
error!("Error getting temperature of fermenter \"{}\": {}", ferm.name, err);
continue;
}
};

info!("Fermenter \"{}\": {:.02} °C", ferm.name, temp_record.temperature);

log_temperature(&brewfather, &mut last_logged, &ferm, temp_record).await;
}
}

sleep(Duration::from_secs(15 * 60 + 1)).await;
Expand Down

0 comments on commit c5b3758

Please sign in to comment.