pub trait TypedWorkflow: WorkflowHandler {
type Input: Serialize + DeserializeOwned + Send;
// Provided method
fn typed_input_schema() -> Option<Value>
where Self: Sized,
Self::Input: JsonSchema { ... }
}Expand description
A WorkflowHandler whose input payload has a declared type.
Implement it on a handler that is called as a sub-workflow:
WorkflowContext::workflow
then only accepts a Self::Input for it, so a parent cannot pass a
misspelled or incomplete payload. Handlers that are never called as a
sub-workflow do not need it.
typed_input_schema derives the JSON Schema of
the input from the same type, for WorkflowHandler::input_schema.
§Examples
use ironflow_engine::config::ShellConfig;
use ironflow_engine::context::WorkflowContext;
use ironflow_engine::error::EngineError;
use ironflow_engine::handler::{HandlerFuture, TypedWorkflow, WorkflowHandler};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Serialize, Deserialize, JsonSchema)]
struct CollectInput {
host: String,
}
struct Collect;
impl WorkflowHandler for Collect {
fn name(&self) -> &str { "collect" }
fn input_schema(&self) -> Option<Value> { Self::typed_input_schema() }
fn execute<'a>(&'a self, ctx: &'a mut WorkflowContext) -> HandlerFuture<'a> {
Box::pin(async move {
let input: CollectInput = ctx.input().await?;
ctx.shell("uptime", ShellConfig::new("ssh \"$HOST\" uptime").env("HOST", &input.host))
.await?;
Ok(())
})
}
}
impl TypedWorkflow for Collect {
type Input = CollectInput;
}
let child = ctx.workflow(&Collect, CollectInput { host: "db-1".to_string() }).await?;
println!("collected by run {}", child.run_id());Required Associated Types§
Sourcetype Input: Serialize + DeserializeOwned + Send
type Input: Serialize + DeserializeOwned + Send
The payload a run of this workflow is started with.
Provided Methods§
Sourcefn typed_input_schema() -> Option<Value>
fn typed_input_schema() -> Option<Value>
JSON Schema of Self::Input, ready to return from
WorkflowHandler::input_schema.
§Examples
use ironflow_engine::context::WorkflowContext;
use ironflow_engine::handler::{HandlerFuture, TypedWorkflow, WorkflowHandler};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, JsonSchema)]
struct DeployInput {
environment: String,
}
struct Deploy;
impl WorkflowHandler for Deploy {
fn name(&self) -> &str { "deploy" }
fn execute<'a>(&'a self, _ctx: &'a mut WorkflowContext) -> HandlerFuture<'a> {
Box::pin(async move { Ok(()) })
}
}
impl TypedWorkflow for Deploy {
type Input = DeployInput;
}
let schema = Deploy::typed_input_schema().expect("a schema");
assert!(schema["properties"]["environment"].is_object());Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".