use std::sync::Arc;
use tokio::time::{interval, Duration};
use crate::traits::{VectorStore};
pub struct ConsolidationWorker {
store: Arc<dyn VectorStore>,
interval_seconds: u64,
}
impl ConsolidationWorker {
pub fn new(store: Arc<dyn VectorStore>, interval_seconds: u64) -> Self {
Self { store, interval_seconds }
}
pub fn start(self) {
let store = self.store.clone();
let interval_seconds = self.interval_seconds;
tokio::spawn(async move {
let mut ticker = interval(Duration::from_secs(interval_seconds));
loop {
ticker.tick().await;
println!("[Consolidation] Sleep cycle starting...");
if let Ok(nodes) = store.get_all_nodes().await {
println!("[Consolidation] Analyzing {} memories...", nodes.len());
tokio::time::sleep(Duration::from_secs(2)).await;
println!("[Consolidation] Refined and pruned semantic space.");
} else {
eprintln!("[Consolidation Error] Could not fetch nodes.");
}
}
});
}
}