Skip to main content

conductor/models/
schedule.rs

1// Copyright {{.Year}} Conductor OSS
2// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// Workflow schedule definition.
8#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct WorkflowSchedule {
11    /// Schedule name (unique identifier).
12    pub name: String,
13
14    /// Cron expression for the schedule.
15    pub cron_expression: String,
16
17    // NOTE: there is deliberately no top-level `workflow_name` / `workflow_version`
18    // here. Neither server family has such a field -- both OSS Conductor
19    // (scheduler/core/.../model/WorkflowSchedule.java) and Orkes Conductor
20    // (scheduler-oss/.../model/WorkflowSchedule.java) carry the workflow name and
21    // version only inside `startWorkflowRequest`. Use `start_workflow_request`.
22    /// Start workflow request parameters
23    #[serde(default)]
24    pub start_workflow_request: Option<StartWorkflowScheduleRequest>,
25
26    /// Whether the schedule is paused.
27    #[serde(default)]
28    pub paused: bool,
29
30    /// Why the schedule is paused, if it was paused with a reason. Server-populated;
31    /// there is no way to set this on save -- see [`SaveScheduleRequest`].
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub paused_reason: Option<String>,
34
35    /// Whether to run tasks that were missed during the paused period.
36    #[serde(default)]
37    pub run_catchup_schedule_instances: bool,
38
39    /// Schedule start time (epoch ms).
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub schedule_start_time: Option<i64>,
42
43    /// Schedule end time (epoch ms).
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub schedule_end_time: Option<i64>,
46
47    /// Timezone for the cron expression.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub zone_id: Option<String>,
50
51    /// Human-readable description.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub description: Option<String>,
54
55    /// Create time (epoch ms).
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub create_time: Option<i64>,
58
59    /// Created by user.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub created_by: Option<String>,
62
63    /// Update time (epoch ms)
64    ///
65    /// The server field is `updatedTime`, not `updateTime`.
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub updated_time: Option<i64>,
68
69    /// Updated by user.
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub updated_by: Option<String>,
72
73    /// Next scheduled run time (epoch ms), if the server has computed one.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub next_run_time: Option<i64>,
76}
77
78/// Start workflow request for schedules.
79#[derive(Debug, Clone, Default, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct StartWorkflowScheduleRequest {
82    /// Workflow name.
83    pub name: String,
84
85    /// Workflow version.
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub version: Option<i32>,
88
89    /// Correlation ID.
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub correlation_id: Option<String>,
92
93    /// Input parameters.
94    #[serde(default)]
95    pub input: HashMap<String, serde_json::Value>,
96
97    /// Task to domain mapping.
98    #[serde(default)]
99    pub task_to_domain: HashMap<String, String>,
100
101    /// Idempotency key.
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub idempotency_key: Option<String>,
104
105    /// Idempotency strategy.
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub idempotency_strategy: Option<String>,
108}
109
110/// Request to save a schedule.
111#[derive(Debug, Clone, Default, Serialize, Deserialize)]
112#[serde(rename_all = "camelCase")]
113pub struct SaveScheduleRequest {
114    /// Schedule name.
115    pub name: String,
116
117    /// Cron expression.
118    pub cron_expression: String,
119
120    /// Start workflow request.
121    pub start_workflow_request: StartWorkflowScheduleRequest,
122
123    /// Whether the schedule is paused.
124    #[serde(default)]
125    pub paused: bool,
126
127    /// Run catchup schedule instances.
128    #[serde(default)]
129    pub run_catchup_schedule_instances: bool,
130
131    /// Schedule start time.
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub schedule_start_time: Option<i64>,
134
135    /// Schedule end time.
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub schedule_end_time: Option<i64>,
138
139    /// Timezone.
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub zone_id: Option<String>,
142
143    /// Human-readable description.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub description: Option<String>,
146}
147
148impl SaveScheduleRequest {
149    /// Create a new save schedule request.
150    pub fn new(
151        name: impl Into<String>,
152        cron_expression: impl Into<String>,
153        workflow_name: impl Into<String>,
154    ) -> Self {
155        Self {
156            name: name.into(),
157            cron_expression: cron_expression.into(),
158            start_workflow_request: StartWorkflowScheduleRequest {
159                name: workflow_name.into(),
160                ..Default::default()
161            },
162            ..Default::default()
163        }
164    }
165
166    /// Set workflow version.
167    #[must_use]
168    pub fn with_version(mut self, version: i32) -> Self {
169        self.start_workflow_request.version = Some(version);
170        self
171    }
172
173    /// Set workflow input.
174    #[must_use]
175    pub fn with_input(mut self, input: HashMap<String, serde_json::Value>) -> Self {
176        self.start_workflow_request.input = input;
177        self
178    }
179
180    /// Set timezone.
181    #[must_use]
182    pub fn with_timezone(mut self, timezone: impl Into<String>) -> Self {
183        self.zone_id = Some(timezone.into());
184        self
185    }
186
187    /// Set paused state.
188    #[must_use]
189    pub fn paused(mut self, paused: bool) -> Self {
190        self.paused = paused;
191        self
192    }
193
194    /// Set whether missed fires should be replayed on resume.
195    #[must_use]
196    pub fn with_catchup(mut self, run_catchup_schedule_instances: bool) -> Self {
197        self.run_catchup_schedule_instances = run_catchup_schedule_instances;
198        self
199    }
200
201    /// Set the schedule's active window start (epoch ms).
202    #[must_use]
203    pub fn with_start_time(mut self, schedule_start_time: i64) -> Self {
204        self.schedule_start_time = Some(schedule_start_time);
205        self
206    }
207
208    /// Set the schedule's active window end (epoch ms).
209    #[must_use]
210    pub fn with_end_time(mut self, schedule_end_time: i64) -> Self {
211        self.schedule_end_time = Some(schedule_end_time);
212        self
213    }
214
215    /// Set a human-readable description.
216    #[must_use]
217    pub fn with_description(mut self, description: impl Into<String>) -> Self {
218        self.description = Some(description.into());
219        self
220    }
221}
222
223/// Schedule execution record.
224#[derive(Debug, Clone, Default, Serialize, Deserialize)]
225#[serde(rename_all = "camelCase")]
226pub struct WorkflowScheduleExecution {
227    /// Execution ID.
228    #[serde(default)]
229    pub execution_id: String,
230
231    /// Schedule name.
232    #[serde(default)]
233    pub schedule_name: String,
234
235    /// Scheduled time.
236    #[serde(default)]
237    pub scheduled_time: i64,
238
239    /// Execution time.
240    #[serde(default)]
241    pub execution_time: i64,
242
243    /// Workflow ID that was started.
244    #[serde(skip_serializing_if = "Option::is_none")]
245    pub workflow_id: Option<String>,
246
247    /// Workflow name.
248    #[serde(default)]
249    pub workflow_name: String,
250
251    /// State of the execution.
252    #[serde(default)]
253    pub state: String,
254
255    /// Reason for failure (if any).
256    #[serde(skip_serializing_if = "Option::is_none")]
257    pub reason: Option<String>,
258}
259
260/// Search result for schedule executions.
261#[derive(Debug, Clone, Default, Serialize, Deserialize)]
262#[serde(rename_all = "camelCase")]
263pub struct SearchResultWorkflowScheduleExecution {
264    /// Total number of hits.
265    #[serde(default)]
266    pub total_hits: i64,
267
268    /// Results.
269    #[serde(default)]
270    pub results: Vec<WorkflowScheduleExecution>,
271}