Skip to main content

swf_core/models/task/
fork_task.rs

1use serde::{Deserialize, Serialize};
2
3use super::{Map, TaskDefinition, TaskDefinitionFields};
4
5/// Represents the configuration of a task that is composed of multiple subtasks to run concurrently
6#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
7pub struct ForkTaskDefinition {
8    /// Gets/sets the configuration of the branches to perform concurrently
9    #[serde(rename = "fork")]
10    pub fork: BranchingDefinition,
11
12    /// Gets/sets the task's common fields
13    #[serde(flatten)]
14    pub common: TaskDefinitionFields,
15}
16impl ForkTaskDefinition {
17    /// Initializes a new ForkTaskDefinition
18    pub fn new(fork: BranchingDefinition) -> Self {
19        Self {
20            fork,
21            common: TaskDefinitionFields::new(),
22        }
23    }
24}
25
26/// Represents an object used to configure branches to perform concurrently
27#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
28pub struct BranchingDefinition {
29    /// Gets/sets a name/definition mapping of the subtasks to perform concurrently
30    #[serde(rename = "branches")]
31    pub branches: Map<String, TaskDefinition>,
32
33    /// Gets/sets a boolean indicating whether or not the branches should compete each other. If `true` and if a branch completes, it will cancel all other branches then it will return its output as the task's output
34    #[serde(rename = "compete")]
35    pub compete: bool,
36}
37impl BranchingDefinition {
38    pub fn new(branches: Map<String, TaskDefinition>, compete: bool) -> Self {
39        Self { branches, compete }
40    }
41}