Skip to main content

alien_core/deployment/
status.rs

1//! Deployment status enum and lifecycle phase checks.
2
3use serde::{Deserialize, Serialize};
4
5/// Deployment status in the deployment lifecycle
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
8#[serde(rename_all = "kebab-case")]
9pub enum DeploymentStatus {
10    Pending,
11    PreflightsFailed,
12    InitialSetup,
13    InitialSetupFailed,
14    Provisioning,
15    ProvisioningFailed,
16    Running,
17    RefreshFailed,
18    UpdatePending,
19    Updating,
20    UpdateFailed,
21    DeletePending,
22    Deleting,
23    DeleteFailed,
24    TeardownRequired,
25    TeardownFailed,
26    Deleted,
27    Error,
28}
29
30impl DeploymentStatus {
31    /// Check if deployment is synced (current state matches desired state).
32    ///
33    /// When synced, no more deployment steps are needed *for the current operation*.
34    /// Note: This doesn't mean the deployment is "done forever":
35    /// - `Running` → heartbeats continue, updates can come
36    /// - `*Failed` → can be retried
37    /// - `Deleted` → can be recreated
38    ///
39    /// "Synced" means: "we've reached the goal of the current deployment phase"
40    pub fn is_synced(&self) -> bool {
41        matches!(
42            self,
43            DeploymentStatus::Running
44                | DeploymentStatus::PreflightsFailed
45                | DeploymentStatus::InitialSetupFailed
46                | DeploymentStatus::ProvisioningFailed
47                | DeploymentStatus::UpdateFailed
48                | DeploymentStatus::DeleteFailed
49                | DeploymentStatus::TeardownRequired
50                | DeploymentStatus::TeardownFailed
51                | DeploymentStatus::RefreshFailed
52                | DeploymentStatus::Deleted
53                | DeploymentStatus::Error
54        )
55    }
56
57    /// Check if deployment is in a failed state that requires retry to proceed.
58    pub fn is_failed(&self) -> bool {
59        matches!(
60            self,
61            DeploymentStatus::PreflightsFailed
62                | DeploymentStatus::InitialSetupFailed
63                | DeploymentStatus::ProvisioningFailed
64                | DeploymentStatus::UpdateFailed
65                | DeploymentStatus::DeleteFailed
66                | DeploymentStatus::TeardownFailed
67                | DeploymentStatus::RefreshFailed
68                | DeploymentStatus::Error
69        )
70    }
71}