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    InitialSetup,
12    InitialSetupFailed,
13    Provisioning,
14    ProvisioningFailed,
15    Running,
16    RefreshFailed,
17    UpdatePending,
18    Updating,
19    UpdateFailed,
20    DeletePending,
21    Deleting,
22    DeleteFailed,
23    Deleted,
24    Error,
25}
26
27impl DeploymentStatus {
28    /// Check if deployment is synced (current state matches desired state).
29    ///
30    /// When synced, no more deployment steps are needed *for the current operation*.
31    /// Note: This doesn't mean the deployment is "done forever":
32    /// - `Running` → heartbeats continue, updates can come
33    /// - `*Failed` → can be retried
34    /// - `Deleted` → can be recreated
35    ///
36    /// "Synced" means: "we've reached the goal of the current deployment phase"
37    pub fn is_synced(&self) -> bool {
38        matches!(
39            self,
40            DeploymentStatus::Running
41                | DeploymentStatus::InitialSetupFailed
42                | DeploymentStatus::ProvisioningFailed
43                | DeploymentStatus::UpdateFailed
44                | DeploymentStatus::DeleteFailed
45                | DeploymentStatus::RefreshFailed
46                | DeploymentStatus::Deleted
47                | DeploymentStatus::Error
48        )
49    }
50
51    /// Check if deployment is in a failed state that requires retry to proceed.
52    pub fn is_failed(&self) -> bool {
53        matches!(
54            self,
55            DeploymentStatus::InitialSetupFailed
56                | DeploymentStatus::ProvisioningFailed
57                | DeploymentStatus::UpdateFailed
58                | DeploymentStatus::DeleteFailed
59                | DeploymentStatus::RefreshFailed
60                | DeploymentStatus::Error
61        )
62    }
63}