failed requests - retry until timeout

This commit is contained in:
Alex Janka 2024-04-25 14:23:10 +10:00
parent ff78898683
commit 5b905129d3
5 changed files with 22 additions and 14 deletions

4
Cargo.lock generated
View file

@ -1155,7 +1155,7 @@ dependencies = [
[[package]] [[package]]
name = "homekit-controller" name = "homekit-controller"
version = "0.6.2" version = "0.6.3"
dependencies = [ dependencies = [
"chacha20poly1305", "chacha20poly1305",
"ed25519-dalek", "ed25519-dalek",
@ -1178,7 +1178,7 @@ dependencies = [
[[package]] [[package]]
name = "homekit-exporter" name = "homekit-exporter"
version = "0.6.2" version = "0.6.3"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "homekit-controller" name = "homekit-controller"
version = "0.6.2" version = "0.6.3"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
description = "Partial implementation of the HomeKit controller protocol" description = "Partial implementation of the HomeKit controller protocol"

View file

@ -306,22 +306,30 @@ impl DeviceConnection {
} }
pub async fn update_characteristics(&mut self) -> Result<(), HomekitError> { pub async fn update_characteristics(&mut self) -> Result<(), HomekitError> {
match tokio::time::timeout( match tokio::time::timeout(Duration::from_secs(METRIC_GATHER_TIMEOUT_SECS), async {
Duration::from_secs(METRIC_GATHER_TIMEOUT_SECS), loop {
self.characteristics_request(true), match self.characteristics_request(true).await {
) Ok(_) => return,
.await
.map_err(|_| HomekitError::Timeout)
.flatten_result()
{
Ok(r) => Ok(r),
Err(e) => { Err(e) => {
log::warn!( log::warn!(
"{}failed to update characteristics: {e:?}", "{}failed to update characteristics: {e:?}",
formatted_name(&self.name) formatted_name(&self.name)
); );
self.socket = None; self.socket = None;
Err(e) }
}
}
})
.await
{
Ok(r) => Ok(r),
Err(_) => {
log::warn!(
"{}timed out updating characteristics",
formatted_name(&self.name)
);
self.socket = None;
Err(HomekitError::Timeout)
} }
} }
} }

View file

@ -1,6 +1,6 @@
[package] [package]
name = "homekit-exporter" name = "homekit-exporter"
version = "0.6.2" version = "0.6.3"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
description = "Prometheus exporter for HomeKit sensors" description = "Prometheus exporter for HomeKit sensors"

View file

@ -1,7 +1,7 @@
# Maintainer: Alex Janka <alex@alexjanka.com> # Maintainer: Alex Janka <alex@alexjanka.com>
pkgname=homekit-logger pkgname=homekit-logger
pkgver=0.6.2 pkgver=0.6.3
pkgrel=1 pkgrel=1
pkgdesc="Prometheus exporter for HomeKit sensors" pkgdesc="Prometheus exporter for HomeKit sensors"
arch=('x86_64' 'aarch64') arch=('x86_64' 'aarch64')