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 /// The step's runner went offline while it was executing.
38 LostZombie,
39}
40
41/// Represents the execution instance of a specific step in a workflow.
42#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow, ToSchema)]
43pub struct StepInstance {
44 /// Unique identifier for this execution of the step.
45 pub id: StepInstanceId,
46 /// Associated workflow run ID.
47 pub run_id: RunId,
48 /// The name assigned to the step in the workflow definition.
49 pub step_name: String,
50 /// The type of step (e.g., 'docker', 'wasm', 'approval').
51 pub step_type: String,
52 /// Current execution status of the step.
53 pub status: StepStatus,
54 /// The loop index if this step is part of an iteration.
55 pub iteration_index: Option<i32>,
56 /// Identifier of the runner executing this step, if assigned.
57 pub runner_id: Option<String>,
58 /// The affinity context key used to group steps on the same runner.
59 pub affinity_context: Option<String>, // For shared/locked affinity
60 /// Timestamp when the step began executing.
61 pub started_at: Option<DateTime<Utc>>,
62 /// Timestamp when the step finished executing.
63 pub finished_at: Option<DateTime<Utc>>,
64 /// The system exit code returned by the step execution, if applicable.
65 pub exit_code: Option<i32>,
66 /// Optional error message if the step failed.
67 pub error: Option<String>,
68 /// The raw DSL specification block for this step.
69 pub spec: Value,
70 /// The resolved parameters passed to the step runner.
71 pub params: Value,
72 /// Timestamp when the step instance was created.
73 pub created_at: DateTime<Utc>,
74}
75
76/// A key-value output generated by a step execution.
77#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow, ToSchema)]
78pub struct StepOutput {
79 /// Associated step instance ID that generated the output.
80 pub step_instance_id: StepInstanceId,
81 /// The name of the output key.
82 pub key: String,
83 /// The JSON value of the output.
84 pub value: Value,
85 /// Whether this output contains sensitive data that should be redacted.
86 pub is_sensitive: bool,
87}
88
89/// A historical record of a status transition for a step instance.
90#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow, ToSchema)]
91pub struct StepStatusHistory {
92 /// Unique identifier for the history record.
93 pub id: i64,
94 /// Associated step instance ID.
95 pub step_instance_id: StepInstanceId,
96 /// The status the step transitioned into.
97 pub status: StepStatus,
98 /// Timestamp when the status transition occurred.
99 pub created_at: DateTime<Utc>,
100}