Made healthcheck async and repeating and action at config-specified interval

This commit is contained in:
Jedrzej Stuczynski
2020-01-08 10:06:36 +00:00
parent d4cba72118
commit 46ce9eaff7
2 changed files with 14 additions and 4 deletions
+7 -3
View File
@@ -1,5 +1,5 @@
use crate::validator::config;
use log::debug;
use log::{debug, trace};
use std::time::Duration;
pub(crate) struct HealthChecker {
@@ -15,10 +15,14 @@ impl HealthChecker {
}
}
pub fn run(self) {
pub async fn run(self) {
debug!(
"healthcheck run. will use directory at: {:?} and run every {:?}",
self.directory_server, self.interval,
)
);
loop {
tokio::time::delay_for(self.interval).await;
trace!("going to perform a healthcheck!");
}
}
}
+7 -1
View File
@@ -1,6 +1,7 @@
use crate::validator::config::Config;
use crate::validator::health_check::HealthChecker;
use log::debug;
use tokio::runtime::Runtime;
pub mod config;
mod health_check;
@@ -20,6 +21,11 @@ impl Validator {
pub fn start(self) {
debug!("validator run");
self.heath_check.run()
let mut rt = Runtime::new().unwrap();
let health_check_future = self.heath_check.run();
rt.block_on(health_check_future);
}
}