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