Skip to main content

FlowEngine

Struct FlowEngine 

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

Event-sourced workflow engine.

Implementations§

Source§

impl FlowEngine

Source

pub async fn continuation_chain( &self, run_id: &str, ) -> Result<Vec<WorkflowRunSnapshot>>

Follow persisted continue-as-new links from run_id in execution order.

Every returned snapshot owns an independent, append-only event stream. Missing successors and cycles fail closed instead of silently returning a partial lineage.

Source

pub async fn drive(&self, run_id: &str) -> Result<WorkflowRunSnapshot>

Replay and dispatch until the execution reaches a terminal state or an open wait, hook, retry, or child-workflow suspension.

A continue-as-new terminal event is followed into its fresh successor segment. The returned snapshot therefore belongs to the active leaf of the execution chain, which can differ from run_id.

Source§

impl FlowEngine

Source

pub async fn resume_hook( &self, run_id: &str, hook_id: &str, payload: Value, ) -> Result<()>

Resume a hook with an external payload.

Redelivery through a durable outbox is idempotent when the hook already contains the same payload, including after the run becomes terminal. A different payload or a different terminal hook resolution is rejected explicitly instead of being mistaken for the committed outcome. When the resolved run continued as new, matching redelivery follows and repairs its active successor.

Source

pub async fn dispose_hook(&self, run_id: &str, hook_id: &str) -> Result<()>

Dispose an active hook without accepting a callback payload.

This is useful when a host withdraws an approval request, expires a webhook token, or closes an external callback route. Redelivery is idempotent when the hook was already disposed. A received or cancelled hook conflicts with disposal and cannot be reported as successful. When the resolved run continued as new, matching redelivery follows and repairs its active successor.

Source

pub async fn resume_hook_by_token( &self, token: &str, payload: Value, ) -> Result<(String, String)>

Resume an active hook by its external token.

Token lookup intentionally covers only active hooks. Durable consumers that need idempotent redelivery after resolution must retain the stable run and hook identities and call Self::resume_hook.

Source

pub async fn dispose_hook_by_token( &self, token: &str, ) -> Result<(String, String)>

Dispose an active hook by its external token.

This mirrors resume_hook_by_token for callback routers that only know the public token.

Source§

impl FlowEngine

Source

pub async fn snapshot(&self, run_id: &str) -> Result<WorkflowRunSnapshot>

Project the current snapshot for run_id from its durable history.

Source

pub async fn history(&self, run_id: &str) -> Result<Vec<FlowEventEnvelope>>

Load the complete durable event history for run_id.

Source

pub async fn list_run_ids(&self) -> Result<Vec<String>>

List all workflow run IDs known to the engine’s store.

Source

pub async fn list_snapshots(&self) -> Result<Vec<WorkflowRunSnapshot>>

Project current snapshots for every workflow run in the store.

Source

pub async fn run_summary(&self) -> Result<WorkflowRunSummary>

Summarize run state across the active store.

Suspension counters include only non-terminal runs, so a cancelled run that still has old suspension history is not reported as actionable.

Source

pub async fn list_open_suspensions( &self, now: DateTime<Utc>, ) -> Result<Vec<WorkflowRunSuspension>>

List open waits, active hooks, signal waits, delayed retries, and child runs.

The due flag on wait and retry suspensions is computed against now. Terminal runs are skipped so cancelled histories do not produce actionable operator work.

Source

pub async fn next_wakeup( &self, now: DateTime<Utc>, ) -> Result<Option<WorkflowRunSuspension>>

Return the earliest open wait or delayed retry across non-terminal runs.

Active hooks and signal waits are intentionally ignored because they do not have a scheduled wake-up time.

Source

pub async fn list_active_hooks(&self) -> Result<Vec<ActiveHookSnapshot>>

List active external callback hooks across non-terminal runs.

Source§

impl FlowEngine

Source

pub async fn request_cancellation( &self, run_id: &str, request: CancellationRequest, ) -> Result<WorkflowRunSnapshot>

Request cleanup-aware cancellation and replay the workflow.

The request atomically makes waits, hooks, and retrying/running steps that existed before it non-actionable and propagates persisted policy to first-class child workflows. Workflow code observes the request through WorkflowContext::cancellation_request, performs host-owned cleanup with stable step identities, and returns RuntimeCommand::Cancel. Repeating the same request is idempotent. When run_id names a continued predecessor, the request repairs and follows durable links to the active successor. A terminal leaf is returned without runtime-build admission; a non-terminal leaf must pass admission before the cancellation event or workflow replay.

Source

pub async fn force_cancel( &self, run_id: &str, reason: Option<String>, ) -> Result<()>

Immediately terminate the active continuation leaf without cleanup.

Source

pub async fn cancel(&self, run_id: &str, reason: Option<String>) -> Result<()>

Backward-compatible immediate cancellation API.

New cleanup-aware workflows should call Self::request_cancellation.

Source

pub async fn terminate_for_timeout( &self, run_id: &str, deadline: DateTime<Utc>, reason: Option<String>, ) -> Result<()>

Immediately terminate a run with a typed timeout outcome.

Source

pub async fn terminate_for_host_shutdown( &self, run_id: &str, reason: Option<String>, ) -> Result<()>

Explicitly abandon a run under a non-resumable host-shutdown policy.

Ordinary process shutdown must not call this method: durable runs should normally remain non-terminal and resume on a replacement host.

Source

pub async fn record_progress( &self, run_id: &str, progress: WorkflowProgress, ) -> Result<()>

Persist a host-reported progress update exactly once on the active leaf.

Persist a parent-to-child reference exactly once on the active leaf.

Source§

impl FlowEngine

Source

pub async fn start(&self, spec: WorkflowSpec, input: Value) -> Result<String>

Start a workflow run and drive it until completion or suspension.

Source

pub async fn start_with_id( &self, run_id: impl Into<String>, spec: WorkflowSpec, input: Value, ) -> Result<String>

Start a workflow run using a caller-provided durable run id.

Reusing the same run_id with the same workflow spec and input is idempotent. A fully terminal execution is acknowledged without runtime build admission; an active leaf still requires its pinned build before replay. Reusing the id with different spec or input returns a conflict.

Source§

impl FlowEngine

Source

pub async fn resume_wait(&self, run_id: &str, wait_id: &str) -> Result<()>

Resume a wait once its timer has fired.

Redelivery is idempotent after the existing wait has completed or its run has become terminal. A resolved wait still drives recovery through any committed continue-as-new boundary, but no second wait_completed event is appended.

Source

pub async fn list_due_waits( &self, now: DateTime<Utc>, ) -> Result<Vec<(String, String)>>

List active waits whose resume_at is at or before now.

Scheduler integrations can use this to inspect due timers before deciding how aggressively to drive them.

Source

pub async fn resume_due_waits( &self, now: DateTime<Utc>, ) -> Result<Vec<(String, String)>>

Complete every due wait and drive the affected workflows.

Returns only the (run_id, wait_id) pairs completed by this call. A wait completed or cancelled by another caller after the due scan is safely skipped.

Source

pub async fn list_due_retries( &self, now: DateTime<Utc>, ) -> Result<Vec<(String, String)>>

List pending step retries whose retry_after is at or before now.

Source

pub async fn list_due_wakeups( &self, now: DateTime<Utc>, ) -> Result<Vec<ScheduledWakeup>>

List all due wait timers and delayed retries through the store boundary.

Source

pub async fn resume_due_retries( &self, now: DateTime<Utc>, ) -> Result<Vec<(String, String)>>

Drive every run with a due step retry.

Source

pub async fn resume_scheduled_run( &self, run_id: &str, now: DateTime<Utc>, ) -> Result<Vec<ScheduledWakeup>>

Resume the due waits and delayed retries for one targeted run.

Unlike the compatibility-wide resume_due_* methods, this path loads only run_id and never performs another global due-wakeup query. The returned records describe the wakeups that were still due when the task began handling.

Source§

impl FlowEngine

Source

pub async fn send_signal( &self, run_id: &str, signal: WorkflowSignal, ) -> Result<WorkflowRunSnapshot>

Durably deliver a named asynchronous signal to an active execution.

The target follows persisted continue-as-new links. Retrying with the same target run ID and signal_id is idempotent across that descendant chain; changing the name or payload is an explicit conflict. New and matching deliveries repair and drive the active leaf, including a successor missing after its predecessor link committed.

Source§

impl FlowEngine

Source

pub fn builder(runtime: Arc<dyn FlowRuntime>) -> FlowEngineBuilder

Create an engine builder for runtime.

Source

pub fn new( store: Arc<dyn FlowEventStore>, runtime: Arc<dyn FlowRuntime>, ) -> Self

Create an engine with the supplied store, runtime, and default limits.

Source

pub fn in_memory(runtime: Arc<dyn FlowRuntime>) -> Self

Create an engine backed by a new in-memory event store.

Source

pub fn store(&self) -> Arc<dyn FlowEventStore>

Clone the engine’s event-store handle.

Source

pub fn observer(&self) -> Arc<dyn FlowEventObserver>

Clone the engine’s event-observer handle.

Source

pub fn runtime_build_compatibility(&self) -> Option<&RuntimeBuildCompatibility>

Return this engine’s explicit runtime-build admission policy.

Source

pub fn supports_runtime_build( &self, required_build_id: Option<&RuntimeBuildId>, ) -> bool

Return whether this engine can replay a pinned or legacy run.

Source

pub async fn runtime_build_id( &self, run_id: &str, ) -> Result<Option<RuntimeBuildId>>

Read the runtime build identity pinned by one run.

Trait Implementations§

Source§

impl Clone for FlowEngine

Source§

fn clone(&self) -> FlowEngine

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

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SqlComparable<Option<T>> for T

Source§

impl<T> SqlComparable<T> for T

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, <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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more