Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

A program and its config: what runs messages.

An Arc inside, so cloning is cheap and a clone runs the same program. with_program is a reload: the engine it returns runs the new program, and this one, with any run in flight, keeps the old.

use dataflow_rs::datavalue::OwnedDataValue;
use dataflow_rs::{Engine, Message};
use serde_json::json;

let engine = Engine::builder()
    .workflow_json(&json!({"id": "w", "tasks": [
        {"id": "t", "function": {"name": "map", "input": {
            "mappings": [{"path": "data.greeting", "logic": "hello"}]}}}
    ]}))
    .build()
    .unwrap();
let mut message = Message::from_json(&json!({}));
let run = engine.run(&mut message).await;
assert_eq!(run.matched(), 1);
let greeting = OwnedDataValue::from(&json!({"greeting": "hello"}));
assert_eq!(message.context().data(), &greeting);

Implementations§

Source§

impl Engine

Source

pub fn new(program: Program, cfg: EngineConfig) -> Self

An engine running program with cfg.

Source

pub fn builder() -> EngineBuilder

A builder starting from the default registry, for a host that does not quarantine: its build fails if any workflow is rejected.

Source

pub async fn run(&self, msg: &mut Message) -> Run

Runs msg with RunOptions::default.

Source

pub async fn run_with(&self, msg: &mut Message, opts: &RunOptions<'_>) -> Run

Runs msg through the program’s Active workflows, those of opts.channel when it names one, in priority order.

The run reads the clock once: metadata.processed_at, every audit entry and every error record carry that reading. Only an observer asking for TIMINGS, or a trace asking for timings, has the clock read again, for the elapsed times it is given. It writes metadata.engine_version, and metadata.channel under a channel, before any workflow runs, and then, with an ErrorContext configured, removes its path’s key: the records there are the run’s own. A workflow whose rollout does not admit opts.routing_bucket is skipped; no bucket is admitted by every rollout. A workflow that stops the run ends it, and the Run says how: TimedOut once opts.deadline passed, Cancelled once opts.cancel was cancelled, and otherwise Stopped with the error that stopped it, whatever its kind: a child run’s timeout that a function returns before this run’s own deadline passed is its task’s failure, not this run’s. An Err a function returns once opts.deadline has passed, or opts.cancel was cancelled, is the run’s limit’s.

With opts.trace set, the Run carries the run’s Trace: the context after the stamps and the reset, then a step for every recorded call, skipped call or workflow and sweep, the step that stopped the run included: the call a limit cut short, or, for a stop as a sweep starts, the engine’s step for the counter it wrote. Its replay is the message’s context on every status.

Source

pub fn compiler(&self) -> Compiler

A compiler with the program’s registry and options, whose workflows link into a program this engine can run.

Source

pub fn with_program(&self, program: Program) -> Self

An engine running program with this engine’s config: a reload. This engine is unchanged.

Source

pub fn program(&self) -> &Program

The program this engine runs.

Trait Implementations§

Source§

impl Clone for Engine

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Engine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The program and the config.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.