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