diff --git a/Cargo.lock b/Cargo.lock index 98b1290..acdf282 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,7 +107,7 @@ dependencies = [ [[package]] name = "serverless_workflow_builders" -version = "1.0.0-alpha6" +version = "1.0.0-alpha6.1" dependencies = [ "serde_json", "serde_yaml", @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "serverless_workflow_core" -version = "1.0.0-alpha6" +version = "1.0.0-alpha6.1" dependencies = [ "serde", "serde_derive", diff --git a/builders/Cargo.toml b/builders/Cargo.toml index ea0c1f0..d315f47 100644 --- a/builders/Cargo.toml +++ b/builders/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serverless_workflow_builders" -version = "1.0.0-alpha6" +version = "1.0.0-alpha6.1" edition = "2021" authors = ["The Serverless Workflow Authors "] description = "Contains services used to build ServerlessWorkflow workflow definitions programatically" @@ -12,6 +12,6 @@ keywords = ["serverless-workflow", "sdk", "builders"] categories = ["config", "parsing", "data-structures", "api-bindings"] [dependencies] -serverless_workflow_core = { path = "../core", version = "1.0.0-alpha6" } +serverless_workflow_core = { path = "../core", version = "1.0.0-alpha6.1" } serde_json = "1.0" serde_yaml = "0.9" \ No newline at end of file diff --git a/builders/src/services/task.rs b/builders/src/services/task.rs index 24f6003..b894e8c 100644 --- a/builders/src/services/task.rs +++ b/builders/src/services/task.rs @@ -1,12 +1,17 @@ use crate::services::authentication::*; +use crate::services::timeout::*; use serverless_workflow_core::models::any::*; use serverless_workflow_core::models::duration::*; use serverless_workflow_core::models::error::*; use serverless_workflow_core::models::event::*; +use serverless_workflow_core::models::input::*; use serverless_workflow_core::models::map::*; +use serverless_workflow_core::models::output::*; use serverless_workflow_core::models::resource::*; use serverless_workflow_core::models::retry::*; +use serverless_workflow_core::models::schema::*; use serverless_workflow_core::models::task::*; +use serverless_workflow_core::models::timeout::*; use std::collections::HashMap; /// Represents the service used to build TaskDefinitions @@ -211,6 +216,39 @@ pub enum TaskDefinitionBuilder{ Wait(WaitTaskDefinitionBuilder) } +/// Defines functionnality common to all TaskDefinitionBuilder implementations +pub trait TaskDefinitionBuilderBase { + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self; + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self; + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder); + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder); + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder); + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder); + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self; + + /// Builds the configured TaskDefinition + fn build(self) -> TaskDefinition; + +} + /// Represents the service used to build CallTaskDefinitions pub struct CalltaskDefinitionBuilder{ task: CallTaskDefinition @@ -238,9 +276,67 @@ impl CalltaskDefinitionBuilder { self.task.with = Some(arguments); self } + +} +impl TaskDefinitionBuilderBase for CalltaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } /// Builds the configures CallTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Call(self.task) } @@ -266,9 +362,67 @@ impl DoTaskDefinitionBuilder { self.task.do_.add(name.to_string(), task); self } + +} +impl TaskDefinitionBuilderBase for DoTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configures DoTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Do(self.task) } @@ -285,8 +439,66 @@ impl EmitTaskDefinitionBuilder { Self { task: EmitTaskDefinition::new(EventEmissionDefinition::new(event)) } } +} +impl TaskDefinitionBuilderBase for EmitTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configures DoTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Emit(self.task) } @@ -331,8 +543,66 @@ impl ForTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for ForTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configured ForTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::For(self.task) } @@ -359,8 +629,66 @@ impl ForkTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for ForkTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configured ForkTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Fork(self.task) } @@ -387,8 +715,75 @@ impl ListenTaskDefinitionBuilder{ self } + /// Configures the iterator used to process the consumed events + pub fn foreach(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut SubscriptionIteratorDefinitionBuilder){ + let mut builder = SubscriptionIteratorDefinitionBuilder::new(); + setup(&mut builder); + self.task.foreach = Some(builder.build()); + self + } + +} +impl TaskDefinitionBuilderBase for ListenTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configured ListenTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Listen(self.task) } @@ -396,6 +791,7 @@ impl ListenTaskDefinitionBuilder{ /// Represents the service used to build RaiseTaskDefinitions pub struct RaiseTaskDefinitionBuilder{ + common: TaskDefinitionFields, builder: Option, reference: Option } @@ -403,7 +799,7 @@ impl RaiseTaskDefinitionBuilder{ /// Initializes a new RaiseTaskDefinitionBuilder pub fn new() -> Self{ - Self { builder: None, reference: None } + Self { common: TaskDefinitionFields::new(), builder: None, reference: None } } /// Sets the error to raise @@ -423,8 +819,66 @@ impl RaiseTaskDefinitionBuilder{ self.reference = Some(reference.to_string()); } +} +impl TaskDefinitionBuilderBase for RaiseTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.common.then = Some(directive.to_string()); + self + } + /// Builds the configured RaiseTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ let mut task = RaiseTaskDefinition::default(); if let Some(builder) = self.builder { let error = builder.build(); @@ -436,6 +890,7 @@ impl RaiseTaskDefinitionBuilder{ else{ panic!("The error to raise must be configured"); } + task.common = self.common; TaskDefinition::Raise(task) } @@ -443,13 +898,14 @@ impl RaiseTaskDefinitionBuilder{ /// Represents the service used to build RunTaskDefinitions pub struct RunTaskDefinitionBuilder{ + common: TaskDefinitionFields, builder : Option } impl RunTaskDefinitionBuilder{ /// Initializes a new RunTaskDefinitionBuilder pub fn new() -> Self{ - Self{ builder: None } + Self{ common: TaskDefinitionFields::new(), builder: None } } /// Configures the task to run the specified container @@ -496,15 +952,74 @@ impl RunTaskDefinitionBuilder{ } } +} +impl TaskDefinitionBuilderBase for RunTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.common.then = Some(directive.to_string()); + self + } + /// Builds the configured RunTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ if let Some(builder) = self.builder { - let process = match builder { + let mut process = match builder { ProcessDefinitionBuilder::Container(builder) => builder.build(), ProcessDefinitionBuilder::Script(builder) => builder.build(), ProcessDefinitionBuilder::Shell(builder) => builder.build(), ProcessDefinitionBuilder::Workflow(builder) => builder.build() }; + process.common = self.common; TaskDefinition::Run(process) } else{ @@ -537,11 +1052,69 @@ impl SetTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for SetTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds a new SetTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Set(self.task) } - + } /// Represents the service used to build SwitchTaskDefinitions @@ -565,8 +1138,66 @@ impl SwitchTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for SwitchTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds a new SwitchTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Switch(self.task) } @@ -601,8 +1232,66 @@ impl TryTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for TryTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds a new TryTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Try(self.task) } @@ -618,9 +1307,67 @@ impl WaitTaskDefinitionBuilder { pub fn new(duration: OneOfDurationOrIso8601Expression) -> Self{ Self { task: WaitTaskDefinition::new(duration) } } + +} +impl TaskDefinitionBuilderBase for WaitTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } /// Builds the configures DoTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Wait(self.task) } @@ -837,6 +1584,63 @@ impl EventFilterDefinitionBuilder{ } +/// Represents the service used to build SubscriptionIteratorDefinitions +pub struct SubscriptionIteratorDefinitionBuilder{ + iterator: SubscriptionIteratorDefinition +} +impl SubscriptionIteratorDefinitionBuilder{ + + /// Initializes a new SubscriptionIteratorDefinitionBuilder + pub fn new() -> Self{ + Self { iterator: SubscriptionIteratorDefinition::new() } + } + + /// Sets the name of the variable used to store the item being enumerated + pub fn with_item(&mut self, variable: &str) -> &mut Self{ + self.iterator.item = Some(variable.to_string()); + self + } + + /// Sets the name of the variable used to store the index of the item being enumerated + pub fn at(&mut self, variable: &str) -> &mut Self{ + self.iterator.at = Some(variable.to_string()); + self + } + + /// Configures the tasks to run for each consumd event/message + pub fn do_(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TaskDefinitionMapBuilder){ + let mut builder = TaskDefinitionMapBuilder::new(); + setup(& mut builder); + self.iterator.do_ = Some(builder.build()); + self + } + + /// Configures the data each iteration outputs + pub fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.iterator.output = Some(builder.build()); + self + } + + /// Configures the data exported with each iteration + pub fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.iterator.export = Some(builder.build()); + self + } + + /// Buils the configures SubscriptionIteratorDefinition + pub fn build(self) -> SubscriptionIteratorDefinition{ + self.iterator + } + +} + /// Represents the service used to build ErrorDefinition pub struct ErrorDefinitionBuilder{ error: ErrorDefinition @@ -1658,4 +2462,100 @@ impl JitterDefinitionBuilder{ self.jitter } +} + +/// Represents the service used to build InputDataModelDefinitions +pub struct InputDataModelDefinitionBuilder{ + input : InputDataModelDefinition +} +impl InputDataModelDefinitionBuilder{ + + /// Initializes a new InputDataModelDefinitionBuilder + pub fn new() -> Self{ + Self{ input: InputDataModelDefinition::default() } + } + + /// Configures the input schema + pub fn with_schema(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut SchemaDefinitionBuilder){ + let mut builder = SchemaDefinitionBuilder::new(); + setup(&mut builder); + self.input.schema = Some(builder.build()); + self + } + + /// Configures the expression used to filter the input + pub fn from(&mut self, expression: AnyValue) -> &mut Self{ + self.input.from = Some(expression); + self + } + + /// Builds the configured InputDataModelDefinition + pub fn build(self) -> InputDataModelDefinition{ + self.input + } + +} + +/// Represents the service used to build OutputDataModelDefinitions +pub struct OutputDataModelDefinitionBuilder{ + output : OutputDataModelDefinition +} +impl OutputDataModelDefinitionBuilder{ + + /// Initializes a new OutputDataModelDefinitionBuilder + pub fn new() -> Self{ + Self{ output: OutputDataModelDefinition::default() } + } + + /// Sets a runtime expression, if any, used to output specific data to the scope data + pub fn as_(&mut self, expression: AnyValue) -> &mut Self{ + self.output.as_ = Some(expression); + self + } + + /// Builds the configured OutputDataModelDefinition + pub fn build(self) -> OutputDataModelDefinition{ + self.output + } + +} + +/// Represents the service used to build SchemaDefinitions +pub struct SchemaDefinitionBuilder{ + schema: SchemaDefinition +} +impl SchemaDefinitionBuilder{ + + /// Initializes a new SchemaDefinitionBuilder + pub fn new() -> Self{ + Self { schema: SchemaDefinition::default() } + } + + /// Sets the schema format + pub fn with_format(&mut self, format: &str) -> &mut Self{ + self.schema.format = format.to_string(); + self + } + + /// Sets the schema resource + pub fn with_resource(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut ExternalResourceDefinitionBuilder){ + let mut builder = ExternalResourceDefinitionBuilder::new(); + setup(&mut builder); + self.schema.resource = Some(builder.build()); + self + } + + /// Sets the schema document + pub fn with_document(&mut self, document: AnyValue) -> &mut Self{ + self.schema.document = Some(document); + self + } + + /// Builds the configured SchemaDefinition + pub fn build(self) -> SchemaDefinition{ + self.schema + } + } \ No newline at end of file diff --git a/core/Cargo.toml b/core/Cargo.toml index 6a30ded..8f83379 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serverless_workflow_core" -version = "1.0.0-alpha6" +version = "1.0.0-alpha6.1" edition = "2021" authors = ["The Serverless Workflow Authors "] description = "Contains Serverless Workflow DSL models" diff --git a/core/src/lib.rs b/core/src/lib.rs index 749c030..36532e9 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -16,14 +16,20 @@ mod unit_tests { let title = Some("fake-title".to_string()); let summary = Some("fake-summary".to_string()); let document = WorkflowDefinitionMetadata::new(namespace, name, version, title.clone(), summary.clone(), None); + let mut call_task = CallTaskDefinition::new("http", None, Some(true)); + call_task.common.then = Some("continue".to_string()); + let do_task = DoTaskDefinition::new(Map::from(vec![("set".to_string(), TaskDefinition::Wait(WaitTaskDefinition::new(OneOfDurationOrIso8601Expression::Duration(Duration::from_milliseconds(200)))))])); let mut workflow = WorkflowDefinition::new(document); workflow.do_ = Map::new(); - workflow.do_.add("callTask".to_string(), TaskDefinition::Call(CallTaskDefinition::new("http", None, Some(true)))); - workflow.do_.add("doTask".to_string(), TaskDefinition::Do(DoTaskDefinition::new(Map::from(vec![("set".to_string(), TaskDefinition::Wait(WaitTaskDefinition::new(OneOfDurationOrIso8601Expression::Duration(Duration::default()))))])))); + workflow.do_.add("callTask".to_string(), TaskDefinition::Call(call_task)); + workflow.do_.add("doTask".to_string(), TaskDefinition::Do(do_task)); let json_serialization_result = serde_json::to_string_pretty(&workflow); let yaml_serialization_result = serde_yaml::to_string(&workflow); assert!(json_serialization_result.is_ok(), "JSON Serialization failed: {:?}", json_serialization_result.err()); assert!(yaml_serialization_result.is_ok(), "YAML Serialization failed: {:?}", yaml_serialization_result.err()); + if let Result::Ok(yaml) = yaml_serialization_result{ + println!("{}", yaml) + } assert_eq!(workflow.document.namespace, namespace); assert_eq!(workflow.document.name, name); assert_eq!(workflow.document.version, version); diff --git a/core/src/models/task.rs b/core/src/models/task.rs index 553a9ee..89ae21f 100644 --- a/core/src/models/task.rs +++ b/core/src/models/task.rs @@ -9,6 +9,9 @@ use crate::models::input::*; use crate::models::resource::*; use crate::models::retry::*; +use super::output::OutputDataModelDefinition; +use super::timeout::OneOfTimeoutDefinitionOrReference; + /// Enumerates all supported task types pub struct TaskType; impl TaskType { @@ -82,11 +85,66 @@ pub enum TaskDefinition{ } /// A trait that all task definitions must implement -pub trait TypedTaskDefinition { +pub trait TaskDefinitionBase { /// Gets the task's type fn task_type(&self) -> &str; } +/// Holds the fields common to all tasks +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct TaskDefinitionFields{ + + /// Gets/sets a runtime expression, if any, used to determine whether or not the execute the task in the current context + #[serde(rename = "if", skip_serializing_if = "Option::is_none")] + pub if_: Option, + + /// Gets/sets the definition, if any, of the task's input data + #[serde(rename = "input", skip_serializing_if = "Option::is_none")] + pub input: Option, + + /// Gets/sets the definition, if any, of the task's output data + #[serde(rename = "output", skip_serializing_if = "Option::is_none")] + pub output: Option, + + /// Gets/sets the optional configuration for exporting data within the task's context + #[serde(rename = "export", skip_serializing_if = "Option::is_none")] + pub export: Option, + + /// Gets/sets the task's timeout, if any + #[serde(rename = "timeout", skip_serializing_if = "Option::is_none")] + pub timeout: Option, + + /// Gets/sets the flow directive to be performed upon completion of the task + #[serde(rename = "then", skip_serializing_if = "Option::is_none")] + pub then: Option, + + /// Gets/sets a key/value mapping of additional information associated with the task + #[serde(rename = "metadata", skip_serializing_if = "Option::is_none")] + pub metadata: Option> + +} +impl Default for TaskDefinitionFields{ + fn default() -> Self { + TaskDefinitionFields::new() + } +} +impl TaskDefinitionFields{ + + /// Initializes a new TaskDefinitionFields + pub fn new() -> Self{ + Self { + if_: None, + input: None, + output: None, + export: None, + timeout: None, + then: None, + metadata: None + } + } + +} + /// Represents the definition of a task used to call a predefined function #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] pub struct CallTaskDefinition{ @@ -101,22 +159,30 @@ pub struct CallTaskDefinition{ /// Gets/sets a boolean indicating whether or not to wait for the called function to return. Defaults to true #[serde(rename = "await", skip_serializing_if = "Option::is_none")] - pub await_: Option + pub await_: Option, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for CallTaskDefinition { +impl TaskDefinitionBase for CallTaskDefinition { fn task_type(&self) -> &str { TaskType::CALL } } impl CallTaskDefinition { + + /// Initializes a new CalltaskDefinition pub fn new(call: &str, with: Option>, await_: Option) -> Self{ Self { call: call.to_string(), with, - await_ + await_, + common: TaskDefinitionFields::new() } } + } /// Represents the configuration of a task that is composed of multiple subtasks to run sequentially @@ -125,20 +191,28 @@ pub struct DoTaskDefinition{ /// Gets/sets a name/definition mapping of the subtasks to perform sequentially #[serde(rename = "do")] - pub do_: Map + pub do_: Map, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for DoTaskDefinition { +impl TaskDefinitionBase for DoTaskDefinition { fn task_type(&self) -> &str { TaskType::DO } } impl DoTaskDefinition { + + /// Initializes a new CalltaskDefinition pub fn new(do_: Map) -> Self{ Self { - do_ + do_, + common: TaskDefinitionFields::new() } } + } /// Represents the configuration of a task used to emit an event @@ -147,18 +221,24 @@ pub struct EmitTaskDefinition{ /// Gets/sets the configuration of an event's emission #[serde(rename = "emit")] - pub emit: EventEmissionDefinition + pub emit: EventEmissionDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields, } -impl TypedTaskDefinition for EmitTaskDefinition { +impl TaskDefinitionBase for EmitTaskDefinition { fn task_type(&self) -> &str { TaskType::EMIT } } impl EmitTaskDefinition { + /// Initializes a new EmitTaskDefinition pub fn new(emit: EventEmissionDefinition) -> Self{ Self { - emit + emit, + common: TaskDefinitionFields::new() } } } @@ -196,20 +276,26 @@ pub struct ForTaskDefinition{ /// Gets/sets the tasks to perform for each item in the collection #[serde(rename = "do")] - pub do_: Map + pub do_: Map, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for ForTaskDefinition { +impl TaskDefinitionBase for ForTaskDefinition { fn task_type(&self) -> &str { TaskType::FOR } } impl ForTaskDefinition { + /// Initializes a new ForTaskDefinition pub fn new(for_: ForLoopDefinition, do_: Map, while_: Option) -> Self{ Self { for_, while_, - do_ + do_, + common: TaskDefinitionFields::new() } } } @@ -252,18 +338,24 @@ pub struct ForkTaskDefinition{ /// Gets/sets the configuration of the branches to perform concurrently #[serde(rename = "fork")] - pub fork: BranchingDefinition + pub fork: BranchingDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for ForkTaskDefinition { +impl TaskDefinitionBase for ForkTaskDefinition { fn task_type(&self) -> &str { TaskType::FORK } } impl ForkTaskDefinition { + /// Initializes a new ForkTaskDefinition pub fn new(fork: BranchingDefinition) -> Self{ Self { - fork + fork, + common: TaskDefinitionFields::new() } } } @@ -296,18 +388,29 @@ pub struct ListenTaskDefinition{ /// Gets/sets the configuration of the listener to use #[serde(rename = "listen")] - pub listen: ListenerDefinition + pub listen: ListenerDefinition, + + ///Gets/sets the configuration of the iterator, if any, for processing each consumed event + #[serde(rename = "foreach")] + pub foreach: Option, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for ListenTaskDefinition { +impl TaskDefinitionBase for ListenTaskDefinition { fn task_type(&self) -> &str { TaskType::LISTEN } } impl ListenTaskDefinition { + /// Initializes a new ListenTaskDefinition pub fn new(listen: ListenerDefinition) -> Self{ Self { - listen + listen, + foreach: None, + common: TaskDefinitionFields::new() } } } @@ -318,13 +421,18 @@ pub struct ListenerDefinition{ /// Gets/sets the listener's target #[serde(rename = "to")] - pub to: EventConsumptionStrategyDefinition + pub to: EventConsumptionStrategyDefinition, + + /// Gets/sets a string that specifies how events are read during the listen operation + #[serde(rename = "read")] + pub read: Option } impl ListenerDefinition { pub fn new(to: EventConsumptionStrategyDefinition) -> Self{ Self{ - to + to, + read: None } } } @@ -335,18 +443,24 @@ pub struct RaiseTaskDefinition{ /// Gets/sets the definition of the error to raise #[serde(rename = "raise")] - pub raise: RaiseErrorDefinition + pub raise: RaiseErrorDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for RaiseTaskDefinition { +impl TaskDefinitionBase for RaiseTaskDefinition { fn task_type(&self) -> &str { TaskType::RAISE } } impl RaiseTaskDefinition { + /// Initializes a new RaiseTaskDefinition pub fn new(raise: RaiseErrorDefinition) -> Self{ Self{ - raise + raise, + common: TaskDefinitionFields::new() } } } @@ -375,18 +489,24 @@ pub struct RunTaskDefinition{ /// Gets/sets the configuration of the process to execute #[serde(rename = "run")] - pub run: ProcessTypeDefinition + pub run: ProcessTypeDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for RunTaskDefinition { +impl TaskDefinitionBase for RunTaskDefinition { fn task_type(&self) -> &str { TaskType::RUN } } impl RunTaskDefinition { + /// Initializes a new RunTaskDefinition pub fn new(run: ProcessTypeDefinition) -> Self{ Self { - run + run, + common: TaskDefinitionFields::new() } } } @@ -637,18 +757,24 @@ pub struct SetTaskDefinition{ /// Gets/sets the data to set #[serde(rename = "set")] - pub set: HashMap + pub set: HashMap, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for SetTaskDefinition { +impl TaskDefinitionBase for SetTaskDefinition { fn task_type(&self) -> &str { TaskType::SET } } impl SetTaskDefinition { + /// Initializes a new SetTaskDefinition pub fn new() -> Self{ Self { - set: HashMap::new() + set: HashMap::new(), + common: TaskDefinitionFields::new() } } } @@ -659,18 +785,24 @@ pub struct SwitchTaskDefinition{ /// Gets/sets the definition of the switch to use #[serde(rename = "switch")] - pub switch: Map + pub switch: Map, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for SwitchTaskDefinition { +impl TaskDefinitionBase for SwitchTaskDefinition { fn task_type(&self) -> &str { TaskType::SWITCH } } impl SwitchTaskDefinition { + /// Initializes a new SwitchTaskDefinition pub fn new() -> Self{ Self { - switch: Map::new() + switch: Map::new(), + common: TaskDefinitionFields::new() } } } @@ -699,21 +831,29 @@ pub struct TryTaskDefinition{ /// Gets/sets the object used to define the errors to catch #[serde(rename = "catch")] - pub catch: ErrorCatcherDefinition + pub catch: ErrorCatcherDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for TryTaskDefinition { +impl TaskDefinitionBase for TryTaskDefinition { fn task_type(&self) -> &str { TaskType::TRY } } impl TryTaskDefinition { + + /// Initializes a new TryTaskDefintion pub fn new(try_: Map, catch: ErrorCatcherDefinition) -> Self{ Self { try_, - catch + catch, + common: TaskDefinitionFields::new() } } + } /// Represents the configuration of a concept used to catch errors @@ -762,18 +902,60 @@ pub struct WaitTaskDefinition{ /// Gets/sets the amount of time to wait before resuming workflow #[serde(rename = "duration")] - pub duration: OneOfDurationOrIso8601Expression + pub duration: OneOfDurationOrIso8601Expression, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for WaitTaskDefinition { +impl TaskDefinitionBase for WaitTaskDefinition { fn task_type(&self) -> &str { TaskType::WAIT } } impl WaitTaskDefinition { + + /// Initializes a new WaitTaskDefinition pub fn new(duration: OneOfDurationOrIso8601Expression) -> Self{ Self { - duration + duration, + common: TaskDefinitionFields::new() } } + +} + +/// Represents the definition of the iterator used to process each event or message consumed by a subscription +#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] +pub struct SubscriptionIteratorDefinition{ + + /// Gets the name of the variable used to store the current item being enumerated + #[serde(rename = "item")] + pub item: Option, + + /// Gets the name of the variable used to store the index of the current item being enumerated + #[serde(rename = "at")] + pub at: Option, + + /// Gets the tasks to perform for each consumed item + #[serde(rename = "do")] + pub do_: Option>, + + /// Gets/sets an object, if any, used to customize the item's output and to document its schema. + #[serde(rename = "output", skip_serializing_if = "Option::is_none")] + pub output: Option, + + /// Gets/sets an object, if any, used to customize the content of the workflow context. + #[serde(rename = "export", skip_serializing_if = "Option::is_none")] + pub export: Option + +} +impl SubscriptionIteratorDefinition{ + + /// Initializes a new SubscriptionIteratorDefinition + pub fn new() -> Self{ + SubscriptionIteratorDefinition::default() + } + } \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy