pub struct Engine { /* private fields */ }Expand description
The workflow orchestration engine.
Holds references to the store, agent provider, and a registry of
WorkflowHandlers.
§Examples
use std::sync::Arc;
use ironflow_engine::engine::Engine;
use ironflow_engine::config::ShellConfig;
use ironflow_engine::handler::{WorkflowHandler, HandlerFuture, WorkflowInfo};
use ironflow_engine::context::WorkflowContext;
use ironflow_store::memory::InMemoryStore;
use ironflow_store::models::TriggerKind;
use ironflow_core::providers::claude::ClaudeCodeProvider;
use serde_json::json;
struct CiWorkflow;
impl WorkflowHandler for CiWorkflow {
fn name(&self) -> &str { "ci" }
fn execute<'a>(&'a self, ctx: &'a mut WorkflowContext) -> HandlerFuture<'a> {
Box::pin(async move {
ctx.shell("test", ShellConfig::new("cargo test")).await?;
Ok(())
})
}
}
let store = Arc::new(InMemoryStore::new());
let provider = Arc::new(ClaudeCodeProvider::new());
let mut engine = Engine::new(store, provider);
engine.register(CiWorkflow)?;
let run = engine.run_handler("ci", TriggerKind::Manual, json!({})).await?;
println!("Run {} completed with status {:?}", run.id, run.status);Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(store: Arc<dyn RunStore>, provider: Arc<dyn AgentProvider>) -> Self
pub fn new(store: Arc<dyn RunStore>, provider: Arc<dyn AgentProvider>) -> Self
Create a new engine with the given store and agent provider.
§Examples
use std::sync::Arc;
use ironflow_engine::engine::Engine;
use ironflow_store::memory::InMemoryStore;
use ironflow_core::providers::claude::ClaudeCodeProvider;
let engine = Engine::new(
Arc::new(InMemoryStore::new()),
Arc::new(ClaudeCodeProvider::new()),
);Sourcepub fn provider(&self) -> &Arc<dyn AgentProvider>
pub fn provider(&self) -> &Arc<dyn AgentProvider>
Returns a reference to the agent provider.
Sourcepub fn register(
&mut self,
handler: impl WorkflowHandler + 'static,
) -> Result<(), EngineError>
pub fn register( &mut self, handler: impl WorkflowHandler + 'static, ) -> Result<(), EngineError>
Register a WorkflowHandler for dynamic workflow execution.
The handler is looked up by WorkflowHandler::name when executing
or enqueuing.
§Errors
Returns EngineError::InvalidWorkflow if a handler with the same
name is already registered.
§Examples
use std::sync::Arc;
use ironflow_engine::engine::Engine;
use ironflow_engine::handler::{WorkflowHandler, HandlerFuture};
use ironflow_engine::context::WorkflowContext;
use ironflow_engine::config::ShellConfig;
use ironflow_store::memory::InMemoryStore;
use ironflow_core::providers::claude::ClaudeCodeProvider;
struct MyWorkflow;
impl WorkflowHandler for MyWorkflow {
fn name(&self) -> &str { "my-workflow" }
fn execute<'a>(&'a self, ctx: &'a mut WorkflowContext) -> HandlerFuture<'a> {
Box::pin(async move {
ctx.shell("step1", ShellConfig::new("echo done")).await?;
Ok(())
})
}
}
let mut engine = Engine::new(
Arc::new(InMemoryStore::new()),
Arc::new(ClaudeCodeProvider::new()),
);
engine.register(MyWorkflow)?;Sourcepub fn register_boxed(
&mut self,
handler: Box<dyn WorkflowHandler>,
) -> Result<(), EngineError>
pub fn register_boxed( &mut self, handler: Box<dyn WorkflowHandler>, ) -> Result<(), EngineError>
Register a pre-boxed workflow handler.
§Errors
Returns EngineError::InvalidWorkflow if a handler with the same
name is already registered.
Sourcepub fn get_handler(&self, name: &str) -> Option<&Arc<dyn WorkflowHandler>>
pub fn get_handler(&self, name: &str) -> Option<&Arc<dyn WorkflowHandler>>
Get a registered handler by name.
Sourcepub fn handler_names(&self) -> Vec<&str>
pub fn handler_names(&self) -> Vec<&str>
List registered handler names.
Sourcepub fn handler_info(&self, name: &str) -> Option<WorkflowInfo>
pub fn handler_info(&self, name: &str) -> Option<WorkflowInfo>
Get detailed info about a registered workflow handler.
Sourcepub async fn run_handler(
&self,
handler_name: &str,
trigger: TriggerKind,
payload: Value,
) -> Result<Run, EngineError>
pub async fn run_handler( &self, handler_name: &str, trigger: TriggerKind, payload: Value, ) -> Result<Run, EngineError>
Execute a registered handler inline.
Creates a run, builds a WorkflowContext, calls the handler’s
execute, and finalizes the run.
§Errors
Returns EngineError::InvalidWorkflow if no handler is registered
with that name. Returns EngineError if execution fails.
§Examples
use std::sync::Arc;
use ironflow_engine::engine::Engine;
use ironflow_store::memory::InMemoryStore;
use ironflow_store::models::TriggerKind;
use ironflow_core::providers::claude::ClaudeCodeProvider;
use serde_json::json;
let run = engine.run_handler("deploy", TriggerKind::Manual, json!({})).await?;Sourcepub async fn enqueue_handler(
&self,
handler_name: &str,
trigger: TriggerKind,
payload: Value,
max_retries: u32,
) -> Result<Run, EngineError>
pub async fn enqueue_handler( &self, handler_name: &str, trigger: TriggerKind, payload: Value, max_retries: u32, ) -> Result<Run, EngineError>
Enqueue a handler-based workflow for worker execution.
The workflow name is stored in the run. The worker looks up the handler by name when executing.
§Errors
Returns EngineError::InvalidWorkflow if no handler is registered.
Sourcepub async fn execute_handler_run(
&self,
run_id: Uuid,
) -> Result<Run, EngineError>
pub async fn execute_handler_run( &self, run_id: Uuid, ) -> Result<Run, EngineError>
Execute a handler-based run (used by the worker after pick_next_pending).
Looks up the handler by the run’s workflow_name and executes it
with a fresh WorkflowContext.
§Errors
Returns EngineError::InvalidWorkflow if no handler matches.
Sourcepub async fn execute_run(&self, run_id: Uuid) -> Result<Run, EngineError>
pub async fn execute_run(&self, run_id: Uuid) -> Result<Run, EngineError>
Execute a run by its ID (used by the worker after pick_next_pending).
Delegates to execute_handler_run.
§Errors
Returns EngineError if the run is not found or execution fails.