pub struct Engine { /* private fields */ }
Expand description
High-performance async workflow engine for message processing.
§Architecture
The engine is designed for async-first operation with Tokio:
- Separation of Concerns: Distinct executors for workflows and tasks
- Shared DataLogic: Single DataLogic instance with Arc for thread-safe sharing
- Arc
: Pre-compiled logic shared across all async tasks - Async Functions: Native async support for I/O-bound operations
§Performance Characteristics
- Zero Runtime Compilation: All logic compiled during initialization
- Zero-Copy Sharing: Arc-wrapped compiled logic shared without cloning
- Optimal for Mixed Workloads: Async I/O with blocking CPU evaluation
- Thread-Safe by Design: All components safe to share across Tokio tasks
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(
workflows: Vec<Workflow>,
custom_functions: Option<HashMap<String, Box<dyn AsyncFunctionHandler + Send + Sync>>>,
) -> Self
pub fn new( workflows: Vec<Workflow>, custom_functions: Option<HashMap<String, Box<dyn AsyncFunctionHandler + Send + Sync>>>, ) -> Self
Creates a new Engine instance with configurable parameters.
§Arguments
workflows
- The workflows to use for processing messagescustom_functions
- Optional custom async function handlers
§Example
use dataflow_rs::{Engine, Workflow};
let workflows = vec![Workflow::from_json(r#"{"id": "test", "name": "Test", "priority": 0, "tasks": [{"id": "task1", "name": "Task 1", "function": {"name": "map", "input": {"mappings": []}}}]}"#).unwrap()];
// Simple usage with defaults
let engine = Engine::new(workflows, None);
Sourcepub async fn process_message(&self, message: &mut Message) -> Result<()>
pub async fn process_message(&self, message: &mut Message) -> Result<()>
Processes a message through workflows that match their conditions.
This async method:
- Iterates through workflows sequentially in deterministic order (sorted by ID)
- Delegates workflow execution to the WorkflowExecutor
- Updates message metadata
§Arguments
message
- The message to process through workflows
§Returns
Result<()>
- Ok(()) if processing succeeded, Err if a fatal error occurred
Sourcepub fn logic_cache(&self) -> &Vec<Arc<CompiledLogic>>
pub fn logic_cache(&self) -> &Vec<Arc<CompiledLogic>>
Get a reference to the compiled logic cache
Auto Trait Implementations§
impl Freeze for Engine
impl !RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl !UnwindSafe for Engine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more