Changed presence and metrics interval to use deadlines rather than fixed delays

This commit is contained in:
Jedrzej Stuczynski
2020-03-10 10:11:59 +00:00
parent a9a3e98801
commit 858481e1d2
3 changed files with 13 additions and 3 deletions
+5 -1
View File
@@ -114,7 +114,8 @@ impl MetricsSender {
fn start(mut self, handle: &Handle) -> JoinHandle<()> {
handle.spawn(async move {
loop {
tokio::time::delay_for(self.sending_delay).await;
// set the deadline in the future
let sending_delay = tokio::time::delay_for(self.sending_delay);
let (received, sent) = self.metrics.acquire_and_reset_metrics().await;
match self.directory_client.metrics_post.post(&MixMetric {
@@ -125,6 +126,9 @@ impl MetricsSender {
Err(err) => error!("failed to send metrics - {:?}", err),
Ok(_) => debug!("sent metrics information"),
}
// wait for however much is left
sending_delay.await;
}
})
}
+4 -1
View File
@@ -69,8 +69,11 @@ impl Notifier {
pub fn start(self, handle: &Handle) -> JoinHandle<()> {
handle.spawn(async move {
loop {
// set the deadline in the future
let sending_delay = tokio::time::delay_for(self.sending_delay);
self.notify();
tokio::time::delay_for(self.sending_delay).await;
// wait for however much is left
sending_delay.await;
}
})
}