From 190cc5bd4e265469ff328d9819c82ab52f3c2768 Mon Sep 17 00:00:00 2001 From: Cosmin Constantin Lazar Date: Fri, 17 May 2024 22:37:19 +0200 Subject: [PATCH 1/3] Remove loop run and add --- config/default.toml | 2 -- src/main.rs | 28 +++++++++------------------- src/settings.rs | 1 - tests/full_flow_insta.rs | 1 - 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/config/default.toml b/config/default.toml index 551c69a..1ffb8d6 100644 --- a/config/default.toml +++ b/config/default.toml @@ -1,5 +1,3 @@ -reporting_interval_secs = 3600 - [mqtt] client_id = "affaldvarme" host = "10.0.1.3" diff --git a/src/main.rs b/src/main.rs index 005ce5b..deca50c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 + ), } } diff --git a/src/settings.rs b/src/settings.rs index 5df2f71..443f340 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -7,7 +7,6 @@ use serde::Deserialize; pub struct Settings { pub mqtt: MQTTConfig, pub affaldvarme: AffaldVarmeConfig, - pub reporting_interval_secs: u64, } impl Settings { diff --git a/tests/full_flow_insta.rs b/tests/full_flow_insta.rs index 7a9c5ff..8edf4a6 100644 --- a/tests/full_flow_insta.rs +++ b/tests/full_flow_insta.rs @@ -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, From d1fc7446da828fd5b2af336bb1b0fce4a9f013e9 Mon Sep 17 00:00:00 2001 From: Cosmin Constantin Lazar Date: Fri, 17 May 2024 22:37:38 +0200 Subject: [PATCH 2/3] Add deploy&run script --- scripts/deploy-latest-and-run.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/deploy-latest-and-run.sh diff --git a/scripts/deploy-latest-and-run.sh b/scripts/deploy-latest-and-run.sh new file mode 100644 index 0000000..cc2fe29 --- /dev/null +++ b/scripts/deploy-latest-and-run.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +image_name="untagged6785/ha-mitaffald" +container_name="ha-mitaffald" + +docker pull $image_name:latest + +echo "Stopping container $container_name" +docker stop $container_name || true + +echo "Removing container $container_name" +docker rm $container_name || true + +echo "Starting new container" +docker run -d --name $container_name -e affaldvarme.address.id -e mqtt.username -e mqtt.password --restart=on-failure:5 $image_name:latest \ No newline at end of file From 22ce3f08a5912a97b694b477952a72b06c69e95a Mon Sep 17 00:00:00 2001 From: Cosmin Constantin Lazar Date: Thu, 23 May 2024 20:10:25 +0200 Subject: [PATCH 3/3] Support `_` as env variable sepparator --- src/settings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings.rs b/src/settings.rs index 443f340..6a565a5 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -14,7 +14,7 @@ impl Settings { let settings = Config::builder() .add_source(File::with_name("config/default.toml")) .add_source(File::with_name("config/secrets.toml").required(false)) - .add_source(Environment::default()) + .add_source(Environment::default().separator("_")) .build()?; settings.try_deserialize()