use crate::observation::{LogPhase, SmokeResult, WatchResult};
use crate::preflight::AbortReason;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::time::Duration;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum StepStatus {
Ok,
Failed,
Unknown,
NotStarted,
}
pub(crate) fn down_may_have_started(status: &StepStatus) -> bool {
!matches!(status, StepStatus::NotStarted)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MaintenancePhase {
Down,
Up,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum StopReason {
Requested,
LockLost,
ConnectFailed(String),
JournalFailed(String),
}
impl fmt::Display for StopReason {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Requested => write!(f, "a stop was requested"),
Self::LockLost => write!(f, "the deploy lock was taken over"),
Self::ConnectFailed(reason) => write!(f, "could not reach the server: {reason}"),
Self::JournalFailed(reason) => write!(f, "could not save the receipt: {reason}"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum DeployOutcome {
Succeeded,
FailedAtStep {
step: usize,
partial_update: bool,
},
StoppedAfterStep {
step: usize,
reason: StopReason,
},
CancelledBeforeChanges,
AbortedBeforeChanges(AbortReason),
Unknown {
step: usize,
reason: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeployEvent {
StepStarted {
index: usize,
name: String,
},
Output {
index: usize,
line: String,
},
StepFinished {
index: usize,
status: StepStatus,
exit_code: Option<i32>,
},
Detached {
index: usize,
},
Interrupted {
index: usize,
reason: String,
},
RunError {
reason: String,
},
Warning {
reason: String,
},
MaintenanceStarted {
phase: MaintenancePhase,
},
MaintenanceOutput {
phase: MaintenancePhase,
line: String,
},
MaintenanceFinished {
phase: MaintenancePhase,
status: StepStatus,
exit_code: Option<i32>,
},
AppLeftDown,
ServerState {
head: Option<String>,
tree_dirty: Option<bool>,
},
NewLogError {
phase: LogPhase,
message: String,
file_line: Option<String>,
},
WatchStarted {
window: Duration,
},
WatchFinished(WatchResult),
SmokeFinished(SmokeResult),
Finished(DeployOutcome),
}