Skip to main content

ironflow_sdk/
schedule_methods.rs

1//! Schedule-related methods for [`IronflowClient`].
2
3use uuid::Uuid;
4
5use ironflow_types::ApiResponse;
6
7use crate::client::IronflowClient;
8use crate::error::Error;
9use crate::types;
10
11impl IronflowClient {
12    /// List all schedules.
13    ///
14    /// # Errors
15    ///
16    /// Returns an error if the HTTP request fails or the response cannot be deserialized.
17    ///
18    /// # Examples
19    ///
20    /// ```no_run
21    /// use ironflow_sdk::IronflowClient;
22    ///
23    /// # async fn example() -> Result<(), ironflow_sdk::Error> {
24    /// let client = IronflowClient::new("https://ironflow.example.com", "key");
25    /// let schedules = client.list_schedules().await?;
26    /// # Ok(())
27    /// # }
28    /// ```
29    pub async fn list_schedules(&self) -> Result<ApiResponse<Vec<types::ScheduleResponse>>, Error> {
30        self.send_envelope(self.get("/api/v1/schedules")).await
31    }
32
33    /// Create a new schedule.
34    ///
35    /// # Errors
36    ///
37    /// Returns an error if the HTTP request fails or the response cannot be deserialized.
38    ///
39    /// # Examples
40    ///
41    /// ```no_run
42    /// use ironflow_sdk::IronflowClient;
43    /// use ironflow_sdk::types::CreateScheduleRequest;
44    ///
45    /// # async fn example() -> Result<(), ironflow_sdk::Error> {
46    /// let client = IronflowClient::new("https://ironflow.example.com", "key");
47    /// let schedule = client.create_schedule(&CreateScheduleRequest {
48    ///     workflow_name: "deploy".to_string(),
49    ///     cron_expression: "0 * * * *".to_string(),
50    ///     inputs: Some(serde_json::json!({})),
51    ///     priority: None,
52    ///     catchup: None,
53    ///     catchup_max: None,
54    ///     catchup_window_secs: None,
55    ///     overlap: None,
56    ///     timezone: Some("Europe/Paris".to_string()),
57    /// }).await?;
58    /// # Ok(())
59    /// # }
60    /// ```
61    pub async fn create_schedule(
62        &self,
63        request: &types::CreateScheduleRequest,
64    ) -> Result<ApiResponse<types::ScheduleResponse>, Error> {
65        self.send_envelope(self.post("/api/v1/schedules").json(request))
66            .await
67    }
68
69    /// Get a schedule by ID.
70    ///
71    /// # Errors
72    ///
73    /// Returns an error if the HTTP request fails or the response cannot be deserialized.
74    ///
75    /// # Examples
76    ///
77    /// ```no_run
78    /// use ironflow_sdk::IronflowClient;
79    /// use uuid::Uuid;
80    ///
81    /// # async fn example() -> Result<(), ironflow_sdk::Error> {
82    /// let client = IronflowClient::new("https://ironflow.example.com", "key");
83    /// let schedule = client.get_schedule(Uuid::nil()).await?;
84    /// # Ok(())
85    /// # }
86    /// ```
87    pub async fn get_schedule(
88        &self,
89        id: Uuid,
90    ) -> Result<ApiResponse<types::ScheduleResponse>, Error> {
91        self.send_envelope(self.get(&format!("/api/v1/schedules/{id}")))
92            .await
93    }
94
95    /// Delete a schedule by ID.
96    ///
97    /// # Errors
98    ///
99    /// Returns an error if the HTTP request fails.
100    ///
101    /// # Examples
102    ///
103    /// ```no_run
104    /// use ironflow_sdk::IronflowClient;
105    /// use uuid::Uuid;
106    ///
107    /// # async fn example() -> Result<(), ironflow_sdk::Error> {
108    /// let client = IronflowClient::new("https://ironflow.example.com", "key");
109    /// client.delete_schedule(Uuid::nil()).await?;
110    /// # Ok(())
111    /// # }
112    /// ```
113    pub async fn delete_schedule(&self, id: Uuid) -> Result<(), Error> {
114        self.send_no_content(self.delete(&format!("/api/v1/schedules/{id}")))
115            .await
116    }
117
118    /// Pause a schedule.
119    ///
120    /// # Errors
121    ///
122    /// Returns an error if the HTTP request fails or the response cannot be deserialized.
123    ///
124    /// # Examples
125    ///
126    /// ```no_run
127    /// use ironflow_sdk::IronflowClient;
128    /// use uuid::Uuid;
129    ///
130    /// # async fn example() -> Result<(), ironflow_sdk::Error> {
131    /// let client = IronflowClient::new("https://ironflow.example.com", "key");
132    /// let schedule = client.pause_schedule(Uuid::nil()).await?;
133    /// # Ok(())
134    /// # }
135    /// ```
136    pub async fn pause_schedule(
137        &self,
138        id: Uuid,
139    ) -> Result<ApiResponse<types::ScheduleResponse>, Error> {
140        self.send_envelope(self.post(&format!("/api/v1/schedules/{id}/pause")))
141            .await
142    }
143
144    /// Resume a schedule.
145    ///
146    /// # Errors
147    ///
148    /// Returns an error if the HTTP request fails or the response cannot be deserialized.
149    ///
150    /// # Examples
151    ///
152    /// ```no_run
153    /// use ironflow_sdk::IronflowClient;
154    /// use uuid::Uuid;
155    ///
156    /// # async fn example() -> Result<(), ironflow_sdk::Error> {
157    /// let client = IronflowClient::new("https://ironflow.example.com", "key");
158    /// let schedule = client.resume_schedule(Uuid::nil()).await?;
159    /// # Ok(())
160    /// # }
161    /// ```
162    pub async fn resume_schedule(
163        &self,
164        id: Uuid,
165    ) -> Result<ApiResponse<types::ScheduleResponse>, Error> {
166        self.send_envelope(self.post(&format!("/api/v1/schedules/{id}/resume")))
167            .await
168    }
169
170    /// Trigger a schedule manually, creating a run.
171    ///
172    /// # Errors
173    ///
174    /// Returns an error if the HTTP request fails or the response cannot be deserialized.
175    ///
176    /// # Examples
177    ///
178    /// ```no_run
179    /// use ironflow_sdk::IronflowClient;
180    /// use uuid::Uuid;
181    ///
182    /// # async fn example() -> Result<(), ironflow_sdk::Error> {
183    /// let client = IronflowClient::new("https://ironflow.example.com", "key");
184    /// let schedule = client.trigger_schedule(Uuid::nil()).await?;
185    /// # Ok(())
186    /// # }
187    /// ```
188    pub async fn trigger_schedule(
189        &self,
190        id: Uuid,
191    ) -> Result<ApiResponse<types::ScheduleResponse>, Error> {
192        self.send_envelope(self.post(&format!("/api/v1/schedules/{id}/trigger")))
193            .await
194    }
195}