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    /// Version of the handler that created this run.
52    pub handler_version: Option<String>,
53}
54
55impl From<Run> for RunResponse {
56    fn from(run: Run) -> Self {
57        RunResponse {
58            id: run.id,
59            workflow_name: run.workflow_name,
60            status: run.status.state,
61            trigger: run.trigger,
62            error: run.error,
63            retry_count: run.retry_count,
64            max_retries: run.max_retries,
65            cost_usd: run.cost_usd,
66            duration_ms: run.duration_ms,
67            created_at: run.created_at,
68            updated_at: run.updated_at,
69            started_at: run.started_at,
70            completed_at: run.completed_at,
71            handler_version: run.handler_version,
72        }
73    }
74}
75
76/// Run detail response — includes steps.
77#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
78#[derive(Debug, Serialize)]
79pub struct RunDetailResponse {
80    /// The run.
81    pub run: RunResponse,
82    /// Associated steps, ordered by position.
83    pub steps: Vec<StepResponse>,
84}
85
86/// Query parameters for listing runs.
87#[cfg_attr(feature = "openapi", derive(utoipa::IntoParams, utoipa::ToSchema))]
88#[derive(Debug, Deserialize)]
89pub struct ListRunsQuery {
90    /// Filter by workflow name.
91    pub workflow: Option<String>,
92    /// Filter by run status.
93    pub status: Option<RunStatus>,
94    /// When `true`, only return runs with at least one step.
95    /// When `false`, only return runs with no steps.
96    pub has_steps: Option<bool>,
97    /// Page number (1-based).
98    pub page: Option<u32>,
99    /// Items per page.
100    pub per_page: Option<u32>,
101}