use crate::child_runner::run_exit::TaskExit;
use crate::id::types::{ChildId, ChildStartCount, Generation, SupervisorPath};
use crate::shutdown::stage::{ShutdownCause, ShutdownPhase};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ChildShutdownStatus {
AlreadyExited,
Graceful,
Aborted,
AbortFailed,
LateReport,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ChildShutdownOutcome {
pub child_id: ChildId,
pub path: SupervisorPath,
pub generation: Generation,
pub child_start_count: ChildStartCount,
pub status: ChildShutdownStatus,
pub cancel_delivered: bool,
pub exit: Option<TaskExit>,
pub phase: ShutdownPhase,
pub reason: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChildShutdownOutcomeInput {
pub child_id: ChildId,
pub path: SupervisorPath,
pub generation: Generation,
pub child_start_count: ChildStartCount,
pub status: ChildShutdownStatus,
pub cancel_delivered: bool,
pub exit: Option<TaskExit>,
pub phase: ShutdownPhase,
pub reason: String,
}
impl ChildShutdownOutcome {
pub fn new(input: ChildShutdownOutcomeInput) -> Self {
Self {
child_id: input.child_id,
path: input.path,
generation: input.generation,
child_start_count: input.child_start_count,
status: input.status,
cancel_delivered: input.cancel_delivered,
exit: input.exit,
phase: input.phase,
reason: input.reason,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ResourceReconcileStatus {
Cleaned,
Recorded,
NotOwned,
Failed,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ShutdownReconcileReport {
pub registry_status: ResourceReconcileStatus,
pub runtime_handle_status: ResourceReconcileStatus,
pub journal_status: ResourceReconcileStatus,
pub metrics_status: ResourceReconcileStatus,
pub socket_status: ResourceReconcileStatus,
#[serde(default)]
pub orphan_slots: Vec<ChildId>,
#[serde(default)]
pub total_slots_checked: usize,
#[serde(default)]
pub verified_clean: bool,
pub warnings: Vec<String>,
}
impl ShutdownReconcileReport {
pub fn core_runtime_completed() -> Self {
Self {
registry_status: ResourceReconcileStatus::Cleaned,
runtime_handle_status: ResourceReconcileStatus::Cleaned,
journal_status: ResourceReconcileStatus::Recorded,
metrics_status: ResourceReconcileStatus::Recorded,
socket_status: ResourceReconcileStatus::NotOwned,
orphan_slots: Vec::new(),
total_slots_checked: 0,
verified_clean: true,
warnings: Vec::new(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ShutdownPipelineReport {
pub cause: ShutdownCause,
pub started_at_unix_nanos: u128,
pub completed_at_unix_nanos: u128,
pub phase: ShutdownPhase,
pub outcomes: Vec<ChildShutdownOutcome>,
pub reconcile: ShutdownReconcileReport,
pub idempotent: bool,
}
impl ShutdownPipelineReport {
pub fn as_idempotent(&self) -> Self {
let mut report = self.clone();
report.idempotent = true;
report
}
}