fix: decouple health monitor from webhook config

Health checks, auto-restarts, and WebSocket notifications now run
unconditionally. Previously the entire health loop was gated on
webhook config, so fresh installs (webhooks disabled) got zero
container monitoring. Webhook HTTP delivery is now fire-and-forget
after the notification is pushed to the UI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-12 22:26:58 +00:00
parent 8fad8d6681
commit 04f1f4a20f
2 changed files with 17 additions and 10 deletions

View File

@@ -147,14 +147,6 @@ pub fn spawn_health_monitor(state: Arc<StateManager>, data_dir: PathBuf) {
loop {
interval.tick().await;
// Check webhook config — if webhooks are disabled or ContainerCrash
// isn't subscribed, skip all health monitoring (no restarts, no notifications)
let webhook_config = webhooks::load_config(&data_dir).await.unwrap_or_default();
if !webhook_config.enabled || !webhook_config.events.contains(&WebhookEvent::ContainerCrash) {
debug!("Health monitor: skipping — webhooks disabled or ContainerCrash not subscribed");
continue;
}
let containers = check_containers().await;
if containers.is_empty() {
continue;
@@ -210,11 +202,26 @@ pub fn spawn_health_monitor(state: Arc<StateManager>, data_dir: PathBuf) {
};
// Keep only the latest 20 notifications
data.notifications.push(notification);
data.notifications.push(notification.clone());
if data.notifications.len() > 20 {
data.notifications = data.notifications.split_off(data.notifications.len() - 20);
}
state_changed = true;
// Fire-and-forget webhook delivery (checks config internally)
let webhook_payload = webhooks::WebhookPayload {
event: WebhookEvent::ContainerCrash,
title: notification.title,
message: notification.message,
timestamp: notification.timestamp,
node_id: String::new(),
details: Some(serde_json::json!({
"container": container.name,
"app_id": container.app_id,
"state": container.state,
})),
};
webhooks::send_webhook(&data_dir, webhook_payload).await;
}
}
}