Engine

Struct Engine 

Source
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

Source

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 messages
  • custom_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);
Source

pub async fn process_message(&self, message: &mut Message) -> Result<()>

Processes a message through workflows that match their conditions.

This async method:

  1. Iterates through workflows sequentially in deterministic order (sorted by ID)
  2. Delegates workflow execution to the WorkflowExecutor
  3. Updates message metadata
§Arguments
  • message - The message to process through workflows
§Returns
  • Result<()> - Ok(()) if processing succeeded, Err if a fatal error occurred
Source

pub fn workflows(&self) -> &Arc<HashMap<String, Workflow>>

Get a reference to the workflows

Source

pub fn datalogic(&self) -> &Arc<DataLogic>

Get a reference to the DataLogic instance

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.