Skip to main content

ironflow_api/entities/
run.rs

1//! Run-related DTOs and query parameters.
2
3use chrono::{DateTime, Utc};
4use ironflow_store::models::{Run, RunStatus, TriggerKind};
5use rust_decimal::Decimal;
6use serde::{Deserialize, Serialize};
7use uuid::Uuid;
8
9use super::StepResponse;
10
11/// Run response DTO — public API representation of a run.
12///
13/// Maps from the internal [`Run`] model, exposing only necessary fields.
14///
15/// # Examples
16///
17/// ```
18/// use ironflow_store::models::{Run, RunStatus, TriggerKind};
19/// use ironflow_api::entities::RunResponse;
20/// ```
21#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
22#[derive(Debug, Serialize, Deserialize)]
23pub struct RunResponse {
24    /// Unique run identifier.
25    pub id: Uuid,
26    /// Workflow name.
27    pub workflow_name: String,
28    /// Current status.
29    pub status: RunStatus,
30    /// How the run was triggered.
31    pub trigger: TriggerKind,
32    /// Optional error message.
33    pub error: Option<String>,
34    /// Number of times retried.
35    pub retry_count: u32,
36    /// Maximum allowed retries.
37    pub max_retries: u32,
38    /// Aggregated cost in USD.
39    #[cfg_attr(feature = "openapi", schema(value_type = f64))]
40    pub cost_usd: Decimal,
41    /// Total duration in milliseconds.
42    pub duration_ms: u64,
43    /// When created.
44    pub created_at: DateTime<Utc>,
45    /// When last updated.
46    pub updated_at: DateTime<Utc>,
47    /// When execution started.
48    pub started_at: Option<DateTime<Utc>>,
49    /// When execution completed.
50    pub completed_at: Option<DateTime<Utc>>,
51}
52
53impl From<Run> for RunResponse {
54    fn from(run: Run) -> Self {
55        RunResponse {
56            id: run.id,
57            workflow_name: run.workflow_name,
58            status: run.status.state,
59            trigger: run.trigger,
60            error: run.error,
61            retry_count: run.retry_count,
62            max_retries: run.max_retries,
63            cost_usd: run.cost_usd,
64            duration_ms: run.duration_ms,
65            created_at: run.created_at,
66            updated_at: run.updated_at,
67            started_at: run.started_at,
68            completed_at: run.completed_at,
69        }
70    }
71}
72
73/// Run detail response — includes steps.
74#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
75#[derive(Debug, Serialize)]
76pub struct RunDetailResponse {
77    /// The run.
78    pub run: RunResponse,
79    /// Associated steps, ordered by position.
80    pub steps: Vec<StepResponse>,
81}
82
83/// Query parameters for listing runs.
84#[cfg_attr(feature = "openapi", derive(utoipa::IntoParams, utoipa::ToSchema))]
85#[derive(Debug, Deserialize)]
86pub struct ListRunsQuery {
87    /// Filter by workflow name.
88    pub workflow: Option<String>,
89    /// Filter by run status.
90    pub status: Option<RunStatus>,
91    /// When `true`, only return runs with at least one step.
92    /// When `false`, only return runs with no steps.
93    pub has_steps: Option<bool>,
94    /// Page number (1-based).
95    pub page: Option<u32>,
96    /// Items per page.
97    pub per_page: Option<u32>,
98}