pub struct Engine { /* private fields */ }
Expand description
High-performance workflow engine for message processing.
§Architecture
The engine features a modular design optimized for both IO-bound and CPU-bound workloads:
- Separation of Concerns: Compiler handles pre-compilation, Executor handles runtime
- Direct DataLogic: Single DataLogic instance per engine for zero contention
- Immutable Workflows: All workflows compiled and cached at initialization
- Pre-compiled Logic: JSONLogic expressions compiled once for optimal performance
§Performance Characteristics
- Zero Runtime Compilation: All logic compiled during initialization
- Cache-Friendly: Compiled logic stored in contiguous memory
- Predictable Latency: No runtime allocations for logic evaluation
- Thread-Safe Design: Applications can safely use multiple engine instances across threads
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(
workflows: Vec<Workflow>,
custom_functions: Option<HashMap<String, Box<dyn FunctionHandler + Send + Sync>>>,
retry_config: Option<RetryConfig>,
) -> Self
pub fn new( workflows: Vec<Workflow>, custom_functions: Option<HashMap<String, Box<dyn FunctionHandler + Send + Sync>>>, retry_config: Option<RetryConfig>, ) -> Self
Creates a new Engine instance with configurable parameters.
§Arguments
workflows
- The workflows to use for processing messagescustom_functions
- Optional custom function handlers (None uses empty map)include_builtins
- Optional flag to include built-in functions (defaults to true if None)retry_config
- Optional retry configuration (uses default if None)
§Example
use dataflow_rs::{Engine, Workflow};
let workflows = vec![Workflow::from_json(r#"{"id": "test", "name": "Test", "priority": 0, "tasks": []}"#).unwrap()];
// Simple usage with defaults
let mut engine = Engine::new(workflows.clone(), None, None);
Creates a new Engine instance with shared function handlers. This is useful when creating multiple engine instances that share the same function registry.
§Arguments
workflows
- The workflows to use for processing messagestask_functions
- Shared function handlers wrapped in Arcretry_config
- Optional retry configuration (uses default if None)
Sourcepub fn process_message(&mut self, message: &mut Message) -> Result<()>
pub fn process_message(&mut self, message: &mut Message) -> Result<()>
Processes a message through workflows that match their conditions.
This method:
- Iterates through workflows sequentially in deterministic order (sorted by ID)
- Evaluates conditions for each workflow right before execution
- Executes matching workflows one after another (not concurrently)
- Updates the message with processing results and audit trail
- Clears the evaluation arena after processing to prevent memory leaks
Workflows are executed sequentially because later workflows may depend on the results of earlier workflows, and their conditions may change based on modifications made by previous workflows.
§Arguments
message
- The message to process
§Returns
Result<()>
- Success or an error if processing failed
Trait Implementations§
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