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#[derive(Debug, Serialize, Deserialize)]
22pub struct RunResponse {
23    /// Unique run identifier.
24    pub id: Uuid,
25    /// Workflow name.
26    pub workflow_name: String,
27    /// Current status.
28    pub status: RunStatus,
29    /// How the run was triggered.
30    pub trigger: TriggerKind,
31    /// Optional error message.
32    pub error: Option<String>,
33    /// Number of times retried.
34    pub retry_count: u32,
35    /// Maximum allowed retries.
36    pub max_retries: u32,
37    /// Aggregated cost in USD.
38    pub cost_usd: Decimal,
39    /// Total duration in milliseconds.
40    pub duration_ms: u64,
41    /// When created.
42    pub created_at: DateTime<Utc>,
43    /// When last updated.
44    pub updated_at: DateTime<Utc>,
45    /// When execution started.
46    pub started_at: Option<DateTime<Utc>>,
47    /// When execution completed.
48    pub completed_at: Option<DateTime<Utc>>,
49}
50
51impl From<Run> for RunResponse {
52    fn from(run: Run) -> Self {
53        RunResponse {
54            id: run.id,
55            workflow_name: run.workflow_name,
56            status: run.status.state,
57            trigger: run.trigger,
58            error: run.error,
59            retry_count: run.retry_count,
60            max_retries: run.max_retries,
61            cost_usd: run.cost_usd,
62            duration_ms: run.duration_ms,
63            created_at: run.created_at,
64            updated_at: run.updated_at,
65            started_at: run.started_at,
66            completed_at: run.completed_at,
67        }
68    }
69}
70
71/// Run detail response — includes steps.
72#[derive(Debug, Serialize)]
73pub struct RunDetailResponse {
74    /// The run.
75    pub run: RunResponse,
76    /// Associated steps, ordered by position.
77    pub steps: Vec<StepResponse>,
78}
79
80/// Query parameters for listing runs.
81#[derive(Debug, Deserialize)]
82pub struct ListRunsQuery {
83    /// Filter by workflow name.
84    pub workflow: Option<String>,
85    /// Filter by run status.
86    pub status: Option<RunStatus>,
87    /// Page number (1-based).
88    pub page: Option<u32>,
89    /// Items per page.
90    pub per_page: Option<u32>,
91}