pub struct FlowEngine { /* private fields */ }Expand description
Event-sourced workflow engine.
Implementations§
Source§impl FlowEngine
impl FlowEngine
pub fn builder(runtime: Arc<dyn FlowRuntime>) -> FlowEngineBuilder
pub fn new( store: Arc<dyn FlowEventStore>, runtime: Arc<dyn FlowRuntime>, ) -> Self
pub fn in_memory(runtime: Arc<dyn FlowRuntime>) -> Self
pub fn store(&self) -> Arc<dyn FlowEventStore>
pub fn observer(&self) -> Arc<dyn FlowEventObserver>
Sourcepub async fn start(&self, spec: WorkflowSpec, input: Value) -> Result<String>
pub async fn start(&self, spec: WorkflowSpec, input: Value) -> Result<String>
Start a workflow run and drive it until completion or suspension.
Sourcepub async fn start_with_id(
&self,
run_id: impl Into<String>,
spec: WorkflowSpec,
input: Value,
) -> Result<String>
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. Reusing it with different spec or input returns a conflict.
Sourcepub async fn resume_wait(&self, run_id: &str, wait_id: &str) -> Result<()>
pub async fn resume_wait(&self, run_id: &str, wait_id: &str) -> Result<()>
Resume a wait once its timer has fired.
Sourcepub async fn resume_hook(
&self,
run_id: &str,
hook_id: &str,
payload: Value,
) -> Result<()>
pub async fn resume_hook( &self, run_id: &str, hook_id: &str, payload: Value, ) -> Result<()>
Resume an active hook with external payload.
Sourcepub async fn dispose_hook(&self, run_id: &str, hook_id: &str) -> Result<()>
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. The workflow is
driven after the disposal event so replay code can observe
WorkflowContext::hook_disposed
and complete, fail, or schedule an alternate path.
Sourcepub async fn resume_hook_by_token(
&self,
token: &str,
payload: Value,
) -> Result<(String, String)>
pub async fn resume_hook_by_token( &self, token: &str, payload: Value, ) -> Result<(String, String)>
Resume an active hook by its external token.
This is the API webhook handlers normally want: the callback receives a
token, while run_id and hook_id remain engine internals.
Sourcepub async fn dispose_hook_by_token(
&self,
token: &str,
) -> Result<(String, String)>
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.
Sourcepub async fn list_due_waits(
&self,
now: DateTime<Utc>,
) -> Result<Vec<(String, String)>>
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.
Sourcepub async fn resume_due_waits(
&self,
now: DateTime<Utc>,
) -> Result<Vec<(String, String)>>
pub async fn resume_due_waits( &self, now: DateTime<Utc>, ) -> Result<Vec<(String, String)>>
Complete every due wait and drive the affected workflows.
Returns the (run_id, wait_id) pairs that were resumed. A wait already
completed by another caller is skipped by Self::resume_wait.
Sourcepub async fn list_due_retries(
&self,
now: DateTime<Utc>,
) -> Result<Vec<(String, String)>>
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.
Sourcepub async fn resume_due_retries(
&self,
now: DateTime<Utc>,
) -> Result<Vec<(String, String)>>
pub async fn resume_due_retries( &self, now: DateTime<Utc>, ) -> Result<Vec<(String, String)>>
Drive every run with a due step retry.
pub async fn cancel(&self, run_id: &str, reason: Option<String>) -> Result<()>
pub async fn snapshot(&self, run_id: &str) -> Result<WorkflowRunSnapshot>
pub async fn history(&self, run_id: &str) -> Result<Vec<FlowEventEnvelope>>
pub async fn list_run_ids(&self) -> Result<Vec<String>>
pub async fn list_snapshots(&self) -> Result<Vec<WorkflowRunSnapshot>>
Sourcepub async fn run_summary(&self) -> Result<WorkflowRunSummary>
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 an old wait or hook in history is not reported as actionable work.
Sourcepub async fn list_open_suspensions(
&self,
now: DateTime<Utc>,
) -> Result<Vec<WorkflowRunSuspension>>
pub async fn list_open_suspensions( &self, now: DateTime<Utc>, ) -> Result<Vec<WorkflowRunSuspension>>
List open waits, active hooks, and pending delayed retries.
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.
Sourcepub async fn next_wakeup(
&self,
now: DateTime<Utc>,
) -> Result<Option<WorkflowRunSuspension>>
pub async fn next_wakeup( &self, now: DateTime<Utc>, ) -> Result<Option<WorkflowRunSuspension>>
Return the earliest open wait or delayed retry across non-terminal runs.
This is useful for hosts that want to sleep until the next scheduler tick instead of polling at a fixed interval. Active hooks are intentionally ignored because they do not have a scheduled wake-up time.
Sourcepub async fn list_active_hooks(&self) -> Result<Vec<ActiveHookSnapshot>>
pub async fn list_active_hooks(&self) -> Result<Vec<ActiveHookSnapshot>>
List active external callback hooks across non-terminal runs.
Callback routers and dashboards can use this to discover public hook tokens and their audit metadata without projecting every run manually. The result is sorted by run ID and hook ID for stable polling output.
Sourcepub async fn drive(&self, run_id: &str) -> Result<WorkflowRunSnapshot>
pub async fn drive(&self, run_id: &str) -> Result<WorkflowRunSnapshot>
Replay and dispatch until the run reaches a terminal state or an open wait/hook suspension.
Trait Implementations§
Source§impl Clone for FlowEngine
impl Clone for FlowEngine
Source§fn clone(&self) -> FlowEngine
fn clone(&self) -> FlowEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more