Skip to content

Commit

Permalink
Remove loop run and add
Browse files Browse the repository at this point in the history
  • Loading branch information
CosminLazar committed May 23, 2024
1 parent 2e9fde7 commit 4d76519
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
2 changes: 0 additions & 2 deletions config/default.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
reporting_interval_secs = 3600

[mqtt]
client_id = "affaldvarme"
host = "10.0.1.3"
Expand Down
28 changes: 9 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,16 @@ use ha_mitaffald::sync_data;

#[tokio::main]
async fn main() {
loop {
println!("Starting data synchronization");
println!("Starting data synchronization");

let settings = Settings::new().expect("Failed to read settings");
let report_interval = tokio::time::Duration::from_secs(settings.reporting_interval_secs);
let report = sync_data(settings).await;
let settings = Settings::new().expect("Failed to read settings");
let report = sync_data(settings).await;

match report {
Ok(_) => println!("Data synchronization completed"),
Err(x) => eprintln!(
"Data synchronization failed (some entities may have been updated), error: {}",
x
),
}

println!(
"Next synchronization will take place at: {}",
chrono::Local::now() + report_interval
);

tokio::time::sleep(report_interval).await;
match report {
Ok(_) => println!("Data synchronization completed"),
Err(x) => eprintln!(
"Data synchronization failed (some entities may have been updated), error: {}",
x
),
}
}
1 change: 0 additions & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use serde::Deserialize;
pub struct Settings {
pub mqtt: MQTTConfig,
pub affaldvarme: AffaldVarmeConfig,
pub reporting_interval_secs: u64,
}

impl Settings {
Expand Down
1 change: 0 additions & 1 deletion tests/full_flow_insta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ async fn smoke_test_insta() {
.await;

let settings = Settings {
reporting_interval_secs: 100,
affaldvarme: AffaldVarmeConfig {
address: Address::Id(AddressId { id: address_id }),
base_url: mit_affald_server_url,
Expand Down

0 comments on commit 4d76519

Please sign in to comment.