use crate::tasks::HeartbeatRegistry;
use arifa::prelude::*;
use std::sync::Arc;
use std::time::Duration;
#[derive(Clone)]
pub struct AppState {
pub arifa: Arc<Arifa>,
pub heartbeats: HeartbeatRegistry<String>,
}
impl AppState {
pub async fn new<T: Into<String>>(node_id: T, redis_url: &str) -> Self {
let node_id: String = node_id.into();
let arifa = Arc::new(
Arifa::new(redis_url, &node_id)
.await
.expect("Failed to init Arifa"),
);
let heartbeats = HeartbeatRegistry::new();
heartbeats.spawn_sweeper(Duration::from_secs(15), Duration::from_secs(60));
Self { arifa, heartbeats }
}
pub async fn shutdown(&self) {
self.arifa.shutdown().await;
}
}