stormchaser_model/dsl/workflow.rs
1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::collections::HashMap;
5
6use super::{Handler, Step, Storage};
7
8/// Root structure representing a parsed workflow definition.
9#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
10pub struct Workflow {
11 /// Indicates if this workflow is a reusable template.
12 #[serde(default)]
13 pub is_template: bool,
14 /// The version of the Stormchaser DSL used.
15 pub dsl_version: String,
16 /// The name of the workflow.
17 pub name: String,
18 /// Optional description of the workflow.
19 pub description: Option<String>,
20 /// Optional cron schedule for triggering the workflow.
21 pub cron: Option<String>,
22 /// External reusable workflows or templates imported.
23 pub libraries: Vec<Library>,
24 /// Custom step definitions imported for this workflow.
25 #[serde(default)]
26 pub step_libraries: Vec<StepLibrary>,
27 /// Sub-workflows included for execution.
28 #[serde(default)]
29 pub includes: Vec<Include>,
30 /// Execution strategy and constraints for the workflow.
31 pub strategy: Option<Strategy>,
32 /// Resource quotas applied to the entire workflow run.
33 pub quotas: Option<Quotas>,
34 /// Storage configurations to provision.
35 pub storage: Vec<Storage>,
36 /// Expected inputs for the workflow.
37 pub inputs: Vec<Input>,
38 /// Outputs to be produced by the workflow.
39 pub outputs: Vec<Output>,
40 /// Event handlers for system or custom events.
41 pub handlers: Vec<Handler>,
42 /// The sequential or parallel steps to execute.
43 pub steps: Vec<Step>,
44 /// Steps to execute if the main workflow fails.
45 pub on_failure: Option<Vec<Step>>,
46 /// Steps to execute regardless of success or failure.
47 pub finally: Option<Vec<Step>>,
48}
49
50/// Import definition for external workflow templates.
51#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
52pub struct Library {
53 /// Alias to use when referencing this library.
54 pub name: String,
55 /// Source URI of the library.
56 pub source: String,
57 /// Specific version or reference of the library.
58 pub version: String,
59 /// Checksum to verify the library's integrity.
60 pub checksum: String,
61}
62
63use super::RetryPolicy;
64
65/// Import definition for external step types.
66#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
67pub struct StepLibrary {
68 /// Alias to use for the imported step type.
69 pub name: String,
70 /// The base step type being imported.
71 pub r#type: String,
72 /// Default parameters applied to the step.
73 #[serde(default)]
74 pub params: HashMap<String, String>,
75 /// Step specification override.
76 #[serde(default)]
77 pub spec: Value,
78 /// Default timeout for the step.
79 pub timeout: Option<String>,
80 /// Whether failures are ignored by default.
81 pub allow_failure: Option<bool>,
82 /// Default retry policy.
83 pub retry: Option<RetryPolicy>,
84}
85
86/// Defines an inclusion of another workflow.
87#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
88pub struct Include {
89 /// Name of the inclusion block.
90 pub name: String,
91 /// Reference to the workflow to include.
92 pub workflow: String,
93 /// Input variables to pass to the included workflow.
94 #[serde(default)]
95 pub inputs: HashMap<String, String>,
96}
97
98/// Execution strategy settings (e.g., parallelism, affinity).
99#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
100pub struct Strategy {
101 /// Runner affinity rules.
102 pub affinity: Option<String>,
103 /// Whether to abort all parallel steps if one fails.
104 pub fail_fast: Option<bool>,
105 /// Maximum number of parallel executions.
106 pub max_parallel: Option<u32>,
107 /// List of allowed processes or capabilities.
108 pub process_allow_list: Option<Vec<String>>,
109}
110
111/// Resource quotas for a run.
112#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
113pub struct Quotas {
114 /// Maximum concurrent steps.
115 pub max_concurrency: Option<u32>,
116 /// Maximum CPU limit.
117 pub max_cpu: Option<String>,
118 /// Maximum memory limit.
119 pub max_memory: Option<String>,
120 /// Maximum storage limit.
121 pub max_storage: Option<String>,
122 /// Maximum duration.
123 pub timeout: Option<String>,
124}
125
126/// Workflow input parameter definition.
127#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
128pub struct Input {
129 /// Name of the input variable.
130 pub name: String,
131 /// Data type of the input.
132 pub r#type: String,
133 /// Description of the input.
134 pub description: Option<String>,
135 /// Default value if not provided.
136 pub default: Option<Value>,
137 /// Regex or validation rule for the input.
138 pub validation: Option<String>,
139 /// Allowed options for enum-like inputs.
140 pub options: Option<Vec<String>>,
141 /// Dynamic query to fetch options.
142 pub query: Option<String>,
143}
144
145/// Workflow output value definition.
146#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
147pub struct Output {
148 /// Name of the output variable.
149 pub name: String,
150 /// CEL Expression to evaluate the output value.
151 pub value: String, // CEL Expression
152}