Skip to main content

stormchaser_model/
step.rs

1//! Workflow step execution models and state.
2
3use crate::id::*;
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8use utoipa::ToSchema;
9
10/// The execution status of a single workflow step.
11#[derive(
12    Debug, Serialize, Deserialize, Clone, sqlx::Type, PartialEq, Eq, ToSchema, schemars::JsonSchema,
13)]
14#[sqlx(type_name = "step_status", rename_all = "snake_case")]
15#[serde(rename_all = "snake_case")]
16pub enum StepStatus {
17    /// The step is waiting for dependencies or an available runner.
18    Pending,
19    /// The runner is unpacking the Stormchaser File System (SFS).
20    UnpackingSfs,
21    /// The step is actively executing on a runner.
22    Running,
23    /// The runner is packing and uploading the modified SFS.
24    PackingSfs,
25    /// The step completed successfully.
26    Succeeded,
27    /// The step encountered a failure during execution.
28    Failed,
29    /// The step failed, but the failure was ignored by policy (e.g. continue-on-error).
30    FailedIgnored,
31    /// The step was skipped because conditions were not met.
32    Skipped,
33    /// The step is paused and waiting for an external event or approval.
34    WaitingForEvent,
35    /// The step was aborted, typically due to the run being cancelled.
36    Aborted,
37}
38
39/// Represents the execution instance of a specific step in a workflow.
40#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow, ToSchema)]
41pub struct StepInstance {
42    /// Unique identifier for this execution of the step.
43    pub id: StepInstanceId,
44    /// Associated workflow run ID.
45    pub run_id: RunId,
46    /// The name assigned to the step in the workflow definition.
47    pub step_name: String,
48    /// The type of step (e.g., 'docker', 'wasm', 'approval').
49    pub step_type: String,
50    /// Current execution status of the step.
51    pub status: StepStatus,
52    /// The loop index if this step is part of an iteration.
53    pub iteration_index: Option<i32>,
54    /// Identifier of the runner executing this step, if assigned.
55    pub runner_id: Option<String>,
56    /// The affinity context key used to group steps on the same runner.
57    pub affinity_context: Option<String>, // For shared/locked affinity
58    /// Timestamp when the step began executing.
59    pub started_at: Option<DateTime<Utc>>,
60    /// Timestamp when the step finished executing.
61    pub finished_at: Option<DateTime<Utc>>,
62    /// The system exit code returned by the step execution, if applicable.
63    pub exit_code: Option<i32>,
64    /// Optional error message if the step failed.
65    pub error: Option<String>,
66    /// The raw DSL specification block for this step.
67    pub spec: Value,
68    /// The resolved parameters passed to the step runner.
69    pub params: Value,
70    /// Timestamp when the step instance was created.
71    pub created_at: DateTime<Utc>,
72}
73
74/// A key-value output generated by a step execution.
75#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow, ToSchema)]
76pub struct StepOutput {
77    /// Associated step instance ID that generated the output.
78    pub step_instance_id: StepInstanceId,
79    /// The name of the output key.
80    pub key: String,
81    /// The JSON value of the output.
82    pub value: Value,
83    /// Whether this output contains sensitive data that should be redacted.
84    pub is_sensitive: bool,
85}
86
87/// A historical record of a status transition for a step instance.
88#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow, ToSchema)]
89pub struct StepStatusHistory {
90    /// Unique identifier for the history record.
91    pub id: i64,
92    /// Associated step instance ID.
93    pub step_instance_id: StepInstanceId,
94    /// The status the step transitioned into.
95    pub status: StepStatus,
96    /// Timestamp when the status transition occurred.
97    pub created_at: DateTime<Utc>,
98}