Skip to main content

swf_core/models/task/
try_task.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use super::{Map, TaskDefinition, TaskDefinitionFields};
5use crate::models::retry::OneOfRetryPolicyDefinitionOrReference;
6
7fn default_catch_as() -> Option<String> {
8    Some("error".to_string())
9}
10
11/// Represents the definition of a task used to try one or more subtasks, and to catch/handle the errors that can potentially be raised during execution
12#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
13pub struct TryTaskDefinition {
14    /// Gets/sets a name/definition map of the tasks to try running
15    #[serde(rename = "try")]
16    pub try_: Map<String, TaskDefinition>,
17
18    /// Gets/sets the object used to define the errors to catch
19    #[serde(rename = "catch")]
20    pub catch: ErrorCatcherDefinition,
21
22    /// Gets/sets the task's common fields
23    #[serde(flatten)]
24    pub common: TaskDefinitionFields,
25}
26impl TryTaskDefinition {
27    /// Initializes a new TryTaskDefintion
28    pub fn new(try_: Map<String, TaskDefinition>, catch: ErrorCatcherDefinition) -> Self {
29        Self {
30            try_,
31            catch,
32            common: TaskDefinitionFields::new(),
33        }
34    }
35}
36
37/// Represents the configuration of a concept used to catch errors
38#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
39pub struct ErrorCatcherDefinition {
40    /// Gets/sets the definition of the errors to catch
41    #[serde(rename = "errors", skip_serializing_if = "Option::is_none")]
42    pub errors: Option<ErrorFilterDefinition>,
43
44    /// Gets/sets the name of the runtime expression variable to save the error as. Defaults to 'error'.
45    #[serde(
46        rename = "as",
47        default = "default_catch_as",
48        skip_serializing_if = "Option::is_none"
49    )]
50    pub as_: Option<String>,
51
52    /// Gets/sets a runtime expression used to determine whether or not to catch the filtered error
53    #[serde(rename = "when", skip_serializing_if = "Option::is_none")]
54    pub when: Option<String>,
55
56    /// Gets/sets a runtime expression used to determine when NOT to catch the filtered error
57    #[serde(rename = "exceptWhen", skip_serializing_if = "Option::is_none")]
58    pub except_when: Option<String>,
59
60    /// Gets/sets the retry policy to use, if any
61    #[serde(rename = "retry", skip_serializing_if = "Option::is_none")]
62    pub retry: Option<OneOfRetryPolicyDefinitionOrReference>,
63
64    /// Gets/sets a name/definition map of the tasks, if any, to run when catching an error
65    #[serde(rename = "do", skip_serializing_if = "Option::is_none")]
66    pub do_: Option<Map<String, TaskDefinition>>,
67}
68
69/// Represents the definition of an error filter
70#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
71pub struct ErrorFilterDefinition {
72    /// Gets/sets the properties that errors to filter must define
73    #[serde(rename = "with", skip_serializing_if = "Option::is_none")]
74    pub with: Option<ErrorFilterProperties>,
75}
76
77/// Represents the specific properties used to filter errors
78#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
79pub struct ErrorFilterProperties {
80    /// Gets/sets the error type to filter by
81    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
82    pub type_: Option<String>,
83
84    /// Gets/sets the error status to filter by
85    #[serde(rename = "status", skip_serializing_if = "Option::is_none")]
86    pub status: Option<Value>,
87
88    /// Gets/sets the error instance to filter by
89    #[serde(rename = "instance", skip_serializing_if = "Option::is_none")]
90    pub instance: Option<String>,
91
92    /// Gets/sets the error title to filter by
93    #[serde(rename = "title", skip_serializing_if = "Option::is_none")]
94    pub title: Option<String>,
95
96    /// Gets/sets the error detail to filter by
97    #[serde(rename = "detail", skip_serializing_if = "Option::is_none")]
98    pub detail: Option<String>,
99}