Skip to content

Commit

Permalink
Another slight patch to avoid burning the CPU (#8)
Browse files Browse the repository at this point in the history
* Another slight patch to avoid burning the CPU

* print the diff i guess?

* forgot the lock file
  • Loading branch information
mikekap committed Aug 16, 2020
1 parent 563872f commit 0bc45ff
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ jobs:
cargo +nightly fmt
if [[ -n "$(git status --porcelain)" ]]; then
echo "Your code is not formatted - please run cargo +nightly fmt";
git diff;
exit 1;
fi
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Next

## 0.1.2
- Remove silly Dockerfile in bundle
- Add version to startup log
- Avoid burning the CPU if the MQTT server is unreachable

## 0.1.1
- Add resync interval
- Add some better log messages
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cargo-features = ["strip"]

[package]
name = "wink-mqtt-rs"
version = "0.1.1"
version = "0.1.2"
authors = ["Mike Kaplinskiy <mike.kaplinskiy@gmail.com>"]
edition = "2018"
license = "CC-BY-4.0"
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

let _guard = init_logger(&matches);

info!(slog_scope::logger(), "starting"; "version" => crate_version!());

let options = init_mqtt_client(&matches)?;
#[cfg(target_arch = "arm")]
let controller = controller::AprontestController::new();
Expand Down
15 changes: 11 additions & 4 deletions src/syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,17 @@ where

async fn run_mqtt(this: Arc<Self>, mut ev: EventLoop) -> () {
loop {
let result = Self::loop_once(this.clone(), &mut ev).await;
if !result.is_ok() {
warn!(slog_scope::logger(), "loop_encountered_error"; "err" => format!("{}", result.unwrap_err()))
}
let should_delay = {
let result = Self::loop_once(this.clone(), &mut ev).await;
let is_ok = result.is_ok();
if !is_ok {
warn!(slog_scope::logger(), "loop_encountered_error"; "err" => format!("{}", result.unwrap_err()));
};
!is_ok
};
if should_delay {
tokio::time::delay_for(Duration::from_millis(200)).await
};
}
}

Expand Down

0 comments on commit 0bc45ff

Please sign in to comment.