Skip to content

Commit 0bc45ff

Browse files
authored
Another slight patch to avoid burning the CPU (#8)
* Another slight patch to avoid burning the CPU * print the diff i guess? * forgot the lock file
1 parent 563872f commit 0bc45ff

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

.github/workflows/branch.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ jobs:
2525
cargo +nightly fmt
2626
if [[ -n "$(git status --porcelain)" ]]; then
2727
echo "Your code is not formatted - please run cargo +nightly fmt";
28+
git diff;
2829
exit 1;
2930
fi

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Next
22

3+
## 0.1.2
4+
- Remove silly Dockerfile in bundle
5+
- Add version to startup log
6+
- Avoid burning the CPU if the MQTT server is unreachable
7+
38
## 0.1.1
49
- Add resync interval
510
- Add some better log messages

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cargo-features = ["strip"]
22

33
[package]
44
name = "wink-mqtt-rs"
5-
version = "0.1.1"
5+
version = "0.1.2"
66
authors = ["Mike Kaplinskiy <[email protected]>"]
77
edition = "2018"
88
license = "CC-BY-4.0"

src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
141141

142142
let _guard = init_logger(&matches);
143143

144+
info!(slog_scope::logger(), "starting"; "version" => crate_version!());
145+
144146
let options = init_mqtt_client(&matches)?;
145147
#[cfg(target_arch = "arm")]
146148
let controller = controller::AprontestController::new();

src/syncer.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,17 @@ where
277277

278278
async fn run_mqtt(this: Arc<Self>, mut ev: EventLoop) -> () {
279279
loop {
280-
let result = Self::loop_once(this.clone(), &mut ev).await;
281-
if !result.is_ok() {
282-
warn!(slog_scope::logger(), "loop_encountered_error"; "err" => format!("{}", result.unwrap_err()))
283-
}
280+
let should_delay = {
281+
let result = Self::loop_once(this.clone(), &mut ev).await;
282+
let is_ok = result.is_ok();
283+
if !is_ok {
284+
warn!(slog_scope::logger(), "loop_encountered_error"; "err" => format!("{}", result.unwrap_err()));
285+
};
286+
!is_ok
287+
};
288+
if should_delay {
289+
tokio::time::delay_for(Duration::from_millis(200)).await
290+
};
284291
}
285292
}
286293

0 commit comments

Comments
 (0)