Skip to main content

swf_runtime/
status.rs

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