pub struct SubWorkflowOutput { /* private fields */ }Expand description
Result of a workflow step.
While planning, no child run is created: run_id is
Uuid::nil and the metrics are zero.
It is also the persisted output of the step, so a stored workflow step
reads back with StepOutput::json.
§Examples
use ironflow_engine::executor::SubWorkflowOutput;
use ironflow_store::entities::RunStatus;
use rust_decimal::Decimal;
use uuid::Uuid;
let run_id = Uuid::now_v7();
let output = SubWorkflowOutput::new(run_id, "collect", RunStatus::Completed, Decimal::ZERO, 1200);
assert_eq!(output.run_id(), run_id);
assert_eq!(output.workflow_name(), "collect");
assert_eq!(output.status(), RunStatus::Completed);
assert_eq!(output.duration_ms(), 1200);Implementations§
Source§impl SubWorkflowOutput
impl SubWorkflowOutput
Sourcepub fn new(
run_id: Uuid,
workflow_name: &str,
status: RunStatus,
cost_usd: Decimal,
duration_ms: u64,
) -> Self
pub fn new( run_id: Uuid, workflow_name: &str, status: RunStatus, cost_usd: Decimal, duration_ms: u64, ) -> Self
Assemble the result of a child run.
§Examples
use ironflow_engine::executor::SubWorkflowOutput;
use ironflow_store::entities::RunStatus;
use rust_decimal::Decimal;
use uuid::Uuid;
let output = SubWorkflowOutput::new(Uuid::nil(), "collect", RunStatus::Warning, Decimal::ONE, 0);
assert_eq!(output.cost_usd(), Decimal::ONE);Sourcepub fn with_error(self, error: impl Into<String>) -> Self
pub fn with_error(self, error: impl Into<String>) -> Self
Attach the error of a child run tolerated by allow_failure.
§Examples
use ironflow_engine::executor::SubWorkflowOutput;
use ironflow_store::entities::RunStatus;
use rust_decimal::Decimal;
use uuid::Uuid;
let output = SubWorkflowOutput::new(Uuid::nil(), "collect", RunStatus::Failed, Decimal::ZERO, 0)
.with_error("boom");
assert_eq!(output.error(), Some("boom"));Sourcepub fn with_output(self, output: Option<Value>) -> Self
pub fn with_output(self, output: Option<Value>) -> Self
Attach the output the child handler set with
set_output.
§Examples
use ironflow_engine::executor::SubWorkflowOutput;
use ironflow_store::entities::RunStatus;
use rust_decimal::Decimal;
use serde_json::json;
use uuid::Uuid;
let output = SubWorkflowOutput::new(Uuid::nil(), "review", RunStatus::Completed, Decimal::ZERO, 0)
.with_output(Some(json!(true)));
assert_eq!(output.output::<bool>()?, Some(true));Sourcepub fn run_id(&self) -> Uuid
pub fn run_id(&self) -> Uuid
The child run, to read its steps from the store. Uuid::nil while
planning.
§Examples
use ironflow_engine::executor::SubWorkflowOutput;
use ironflow_store::entities::RunStatus;
use rust_decimal::Decimal;
use uuid::Uuid;
let output = SubWorkflowOutput::new(Uuid::nil(), "collect", RunStatus::Completed, Decimal::ZERO, 0);
assert!(output.run_id().is_nil());Sourcepub fn workflow_name(&self) -> &str
pub fn workflow_name(&self) -> &str
Name of the child workflow.
Sourcepub fn status(&self) -> RunStatus
pub fn status(&self) -> RunStatus
Final status of the child run: Completed, Warning when one of its
allow_failure steps failed, or (only when the step was started with
allow_failure) Failed / Cancelled.
Sourcepub fn cost_usd(&self) -> Decimal
pub fn cost_usd(&self) -> Decimal
Cost of the child run, in USD. Already included in the parent’s cost.
Sourcepub fn duration_ms(&self) -> u64
pub fn duration_ms(&self) -> u64
Wall-clock duration of the child run, in milliseconds.
Sourcepub fn error(&self) -> Option<&str>
pub fn error(&self) -> Option<&str>
Error of a failed or cancelled child run tolerated by allow_failure,
None otherwise.
§Examples
use ironflow_engine::executor::SubWorkflowOutput;
use ironflow_store::entities::RunStatus;
use rust_decimal::Decimal;
use uuid::Uuid;
let output = SubWorkflowOutput::new(Uuid::nil(), "collect", RunStatus::Completed, Decimal::ZERO, 0);
assert_eq!(output.error(), None);Sourcepub fn output<T: DeserializeOwned>(&self) -> Result<Option<T>, EngineError>
pub fn output<T: DeserializeOwned>(&self) -> Result<Option<T>, EngineError>
The typed output the child handler set with
set_output.
Ok(None) when the child set no output. A failed child tolerated by
allow_failure keeps the output it set before failing. On replay the
value is read from the recorded step, not from the child run.
§Errors
Returns EngineError::Serialization if the output does not
deserialize into T.
§Examples
use ironflow_engine::executor::SubWorkflowOutput;
use ironflow_store::entities::RunStatus;
use rust_decimal::Decimal;
use serde::Deserialize;
use serde_json::json;
use uuid::Uuid;
#[derive(Deserialize)]
struct Review {
approved: bool,
}
let child = SubWorkflowOutput::new(Uuid::nil(), "review", RunStatus::Completed, Decimal::ZERO, 0)
.with_output(Some(json!({"approved": true})));
let review: Option<Review> = child.output()?;
assert!(review.is_some_and(|r| r.approved));