1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! [`TriggerKind`] — how a run was triggered.
use serde::{Deserialize, Serialize};
use uuid::Uuid;
/// How a run was triggered.
///
/// # Examples
///
/// ```
/// use ironflow_store::entities::TriggerKind;
///
/// let trigger = TriggerKind::Manual;
/// let json = serde_json::to_string(&trigger).unwrap();
/// assert!(json.contains("manual"));
/// ```
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "kind")]
pub enum TriggerKind {
/// Triggered manually (CLI or programmatic call).
Manual,
/// Triggered by an incoming webhook.
Webhook {
/// The webhook path that received the request.
path: String,
},
/// Triggered by a cron schedule.
Cron {
/// The cron expression that fired.
schedule: String,
},
/// Triggered via the REST API.
Api,
/// Retry of a previously failed run.
Retry {
/// The original run that failed.
parent_run_id: Uuid,
},
/// Triggered by a parent workflow as a sub-workflow step.
Workflow,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serde_roundtrip() {
let triggers = vec![
TriggerKind::Manual,
TriggerKind::Api,
TriggerKind::Webhook {
path: "/hooks/gh".to_string(),
},
TriggerKind::Cron {
schedule: "0 */5 * * * *".to_string(),
},
TriggerKind::Retry {
parent_run_id: Uuid::nil(),
},
];
for trigger in triggers {
let json = serde_json::to_string(&trigger).expect("serialize");
let back: TriggerKind = serde_json::from_str(&json).expect("deserialize");
assert_eq!(trigger, back);
}
}
}