Split refreshing of mixnode cache into a separate task

This commit is contained in:
Mark Sinclair
2021-10-06 20:47:57 +01:00
parent b2ec19ece4
commit a5091cd124
2 changed files with 27 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
pub(crate) mod tasks;
mod utils;
use std::collections::HashMap;
+26
View File
@@ -0,0 +1,26 @@
use crate::state::ExplorerApiStateContext;
pub(crate) struct MixNodesTasks {
state: ExplorerApiStateContext,
}
impl MixNodesTasks {
pub(crate) fn new(state: ExplorerApiStateContext) -> Self {
MixNodesTasks { state }
}
pub(crate) fn start(self) {
info!("Spawning mix nodes task runner...");
tokio::spawn(async move {
let mut interval_timer = tokio::time::interval(std::time::Duration::from_secs(60 * 60)); // every hour
loop {
// wait for the next interval tick
interval_timer.tick().await;
info!("Updating mix node cache...");
self.state.inner.mix_nodes.refresh().await;
info!("Done");
}
});
}
}