From f4d184ccb01b585ba4220ae70b469ddac404f302 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Tue, 14 Sep 2021 16:44:20 -0600 Subject: [PATCH] replace todo with actual notify call --- appmgr/src/status/mod.rs | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/appmgr/src/status/mod.rs b/appmgr/src/status/mod.rs index 557db3404..e57a49137 100644 --- a/appmgr/src/status/mod.rs +++ b/appmgr/src/status/mod.rs @@ -13,6 +13,7 @@ use crate::context::RpcContext; use crate::db::model::CurrentDependencyInfo; use crate::dependencies::DependencyError; use crate::manager::{Manager, Status as ManagerStatus}; +use crate::notifications::{notify, NotificationLevel, NotificationSubtype}; use crate::s9pk::manifest::{Manifest, PackageId}; use crate::status::health_check::HealthCheckResultVariant; use crate::Error; @@ -267,21 +268,35 @@ impl MainStatus { &manifest.volumes, ) .await?; + let mut should_stop = false; for (check, res) in health { - if matches!( - res.result, - health_check::HealthCheckResultVariant::Failure { .. } - ) && manifest - .health_checks - .0 - .get(check) - .map(|hc| hc.critical) - .unwrap_or_default() - { - todo!("emit notification"); - *self = MainStatus::Stopping; + match &res.result { + health_check::HealthCheckResultVariant::Failure { error } + if manifest + .health_checks + .0 + .get(check) + .map(|hc| hc.critical) + .unwrap_or_default() => + { + notify( + &ctx.secret_store, + &ctx.db, + Some(manifest.id.clone()), + NotificationLevel::Error, + String::from("Critical Health Check Failed"), + format!("{} was shut down because a health check required for its operation failed\n{}", manifest.title, error), + NotificationSubtype::General + ) + .await?; + should_stop = true; + } + _ => (), } } + if should_stop { + *self = MainStatus::Stopping; + } } _ => (), }