Implement simple persistent cache with automatic saving on status changes
This commit is contained in:
@@ -9,7 +9,6 @@ use chrono::Utc;
|
||||
pub struct HostStatusConfig {
|
||||
pub enabled: bool,
|
||||
pub aggregation_method: String, // "worst_case"
|
||||
pub update_interval_seconds: u64,
|
||||
pub notification_interval_seconds: u64,
|
||||
}
|
||||
|
||||
@@ -18,7 +17,6 @@ impl Default for HostStatusConfig {
|
||||
Self {
|
||||
enabled: true,
|
||||
aggregation_method: "worst_case".to_string(),
|
||||
update_interval_seconds: 5,
|
||||
notification_interval_seconds: 30,
|
||||
}
|
||||
}
|
||||
@@ -72,7 +70,7 @@ impl HostStatusManager {
|
||||
|
||||
/// Update the status of a specific service and recalculate host status
|
||||
/// Updates real-time status and buffers changes for email notifications
|
||||
pub fn update_service_status(&mut self, service: String, status: Status) {
|
||||
pub fn update_service_status(&mut self, service: String, status: Status, cache_manager: Option<&crate::cache::MetricCacheManager>) {
|
||||
if !self.config.enabled {
|
||||
return;
|
||||
}
|
||||
@@ -84,6 +82,14 @@ impl HostStatusManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// Save cache when status changes (clone cache manager reference for async)
|
||||
if let Some(cache) = cache_manager {
|
||||
let cache = cache.clone();
|
||||
tokio::spawn(async move {
|
||||
cache.save_to_disk().await;
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize batch if this is the first change
|
||||
if self.batch_start_time.is_none() {
|
||||
self.batch_start_time = Some(Instant::now());
|
||||
@@ -163,9 +169,9 @@ impl HostStatusManager {
|
||||
|
||||
|
||||
/// Process a metric - updates status (notifications handled separately via batching)
|
||||
pub async fn process_metric(&mut self, metric: &Metric, _notification_manager: &mut crate::notifications::NotificationManager) {
|
||||
pub async fn process_metric(&mut self, metric: &Metric, _notification_manager: &mut crate::notifications::NotificationManager, cache_manager: &crate::cache::MetricCacheManager) {
|
||||
// Just update status - notifications are handled by process_pending_notifications
|
||||
self.update_service_status(metric.name.clone(), metric.status);
|
||||
self.update_service_status(metric.name.clone(), metric.status, Some(cache_manager));
|
||||
}
|
||||
|
||||
/// Process pending notifications - call this at notification intervals
|
||||
|
||||
Reference in New Issue
Block a user