Expand description
§Task API - Simplified Workflow Interface
This module provides the Task trait, which offers a simplified interface for workflow processing.
A Task only requires implementing a single run method, giving you direct control over the execution flow.
§Key Differences
Task: Simple interface with a singlerunmethod. It’s great for straightforward operations and quick prototyping.crate::node::Node: A more structured interface with a three-phase lifecycle (prep,exec,post). It’s ideal for complex operations where separating concerns is beneficial.
Both Task and Node support retry strategies.
§Relationship & Compatibility
Every crate::node::Node automatically implements Task through a blanket implementation. This means:
- You can use any existing
Nodewherever aTaskis expected. - Workflows can register both
Tasks andNodes using the sameregister()method. - This provides a seamless migration path from a simple
Taskto a more structuredNodeif complexity increases.
§When to Use Which
- Use
Taskfor simplicity and direct control. - Use
crate::node::Nodefor complex logic that benefits from a structured, multi-phase approach.
§Example
use cano::prelude::*;
// Simple Task implementation
struct SimpleTask;
#[async_trait]
impl Task<String> for SimpleTask {
async fn run(&self, store: &MemoryStore) -> Result<TaskResult<String>, CanoError> {
// Do all your work here - load, process, store
let input: String = store.get("input")?;
let result = format!("processed: {input}");
store.put("result", result)?;
Ok(TaskResult::Single("next_state".to_string()))
}
}§Interoperability
Every crate::node::Node automatically implements Task, so you can use existing nodes
wherever tasks are expected. This provides a smooth upgrade path and backward compatibility.
Structs§
- Task
Config - Task configuration for retry behavior and parameters
Enums§
- Retry
Mode - Retry modes for task execution
- Task
Result - Result type for task execution that supports both single and split transitions
Traits§
- DynTask
- Concrete task trait object with default types
- Task
- Task trait for simplified workflow processing
Functions§
- run_
with_ retries - Default implementation for retry logic that can be used by any task
Type Aliases§
- Default
Task Params - Simple key-value parameters for task configuration
- Task
Object - Type alias for trait objects