Skip to main content

ironflow_api/entities/
workflow_pause.rs

1//! Workflow pause response DTO.
2
3use chrono::{DateTime, Utc};
4use serde::Serialize;
5use uuid::Uuid;
6
7use ironflow_store::entities::WorkflowPause;
8
9/// Response of `POST /api/v1/workflows/:name/pause` and
10/// `POST /api/v1/workflows/:name/resume`.
11///
12/// # Examples
13///
14/// ```
15/// use ironflow_api::entities::WorkflowPauseResponse;
16///
17/// let response = WorkflowPauseResponse::resumed("deploy");
18/// assert!(response.paused_at.is_none());
19/// ```
20#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
21#[derive(Debug, Serialize)]
22pub struct WorkflowPauseResponse {
23    /// Workflow name.
24    pub workflow_name: String,
25    /// When the workflow was paused: its queued runs are not picked up until
26    /// it is resumed. Omitted when the workflow is not paused.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub paused_at: Option<DateTime<Utc>>,
29    /// User who paused the workflow, when known.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub paused_by: Option<Uuid>,
32}
33
34impl WorkflowPauseResponse {
35    /// Response for a workflow that is no longer paused.
36    ///
37    /// # Examples
38    ///
39    /// ```
40    /// use ironflow_api::entities::WorkflowPauseResponse;
41    ///
42    /// let response = WorkflowPauseResponse::resumed("deploy");
43    /// assert_eq!(response.workflow_name, "deploy");
44    /// assert!(response.paused_at.is_none());
45    /// ```
46    pub fn resumed(workflow_name: &str) -> Self {
47        Self {
48            workflow_name: workflow_name.to_string(),
49            paused_at: None,
50            paused_by: None,
51        }
52    }
53}
54
55impl From<WorkflowPause> for WorkflowPauseResponse {
56    fn from(pause: WorkflowPause) -> Self {
57        Self {
58            workflow_name: pause.workflow_name,
59            paused_at: Some(pause.paused_at),
60            paused_by: pause.paused_by,
61        }
62    }
63}