use std::thread;
use std::time::{Duration, Instant};
use super::cache::StoreCacheFlush;
pub struct StoreFlushBuilder;
pub struct StoreFlush;
const FLUSH_PERFORM_INTERVAL: Duration = Duration::from_secs(20);
impl StoreFlushBuilder {
pub fn new() -> StoreFlush {
StoreFlush {}
}
}
impl StoreFlush {
#[tokio::main]
pub async fn run(&self) {
info!("store flusher is now active");
loop {
thread::sleep(FLUSH_PERFORM_INTERVAL);
debug!("running a store flush...");
let flush_start = Instant::now();
Self::perform().await;
let flush_took = flush_start.elapsed();
info!(
"ran store flush (took {}s + {}ms)",
flush_took.as_secs(),
flush_took.subsec_millis()
);
}
}
async fn perform() {
StoreCacheFlush::expire();
StoreCacheFlush::refresh().await;
}
}