1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/// Represents the execution status phase of a workflow or task
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum StatusPhase {
/// The workflow/task has been initiated and is pending execution
Pending,
/// The workflow/task is currently in progress
Running,
/// The workflow/task execution is temporarily paused
Waiting,
/// The workflow/task execution has been manually paused
Suspended,
/// The workflow/task execution has been terminated before completion
Cancelled,
/// The workflow/task execution has encountered an error
Faulted,
/// The workflow/task ran to completion
Completed,
}
impl StatusPhase {
/// Returns the string representation of the status phase
pub fn as_str(&self) -> &'static str {
match self {
StatusPhase::Pending => "pending",
StatusPhase::Running => "running",
StatusPhase::Waiting => "waiting",
StatusPhase::Suspended => "suspended",
StatusPhase::Cancelled => "cancelled",
StatusPhase::Faulted => "faulted",
StatusPhase::Completed => "completed",
}
}
}
impl std::fmt::Display for StatusPhase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
/// A log entry recording a status phase transition with timestamp
#[derive(Debug, Clone, PartialEq)]
pub struct StatusPhaseLog {
/// Unix timestamp in milliseconds
pub timestamp: i64,
/// The status phase
pub status: StatusPhase,
}
impl StatusPhaseLog {
/// Creates a new status phase log entry with the current timestamp
pub fn new(status: StatusPhase) -> Self {
Self {
timestamp: chrono::Utc::now().timestamp_millis(),
status,
}
}
}