Skip to main content

WorkflowInstance

Struct WorkflowInstance 

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

Workflow instance (runtime state)

Corresponds to Lean: structure WorkflowInstance

Uses dense arrays indexed by node position for O(1) state access. Maintains counters for O(1) aggregate queries.

Implementations§

Source§

impl WorkflowInstance

Source

pub fn new( workflow_def: WorkflowDef, timeout_at: Time, max_retries: u64, ) -> Self

Create a new workflow instance

Source

pub fn running(timeout_at: Time) -> Self

Create a simple running workflow instance with specified timeout

Useful for tests where we just need a running workflow.

Source

pub fn is_running(&self) -> bool

Check if this workflow is running

Convenience method that delegates to status().is_running()

Source

pub fn get_node_state(&self, n: u64) -> NodeState

Get node state by node ID.

Returns Pending for nodes that exist in the definition but have no explicit state entry yet. For nodes NOT in the definition, also returns Pending (callers should use require_node() first for validation).

Source

pub fn is_pending(&self, n: u64) -> bool

Check if node is in pending state

Corresponds to Lean: def WorkflowInstance.is_pending

Source

pub fn is_active(&self, n: u64) -> bool

Check if node is in active state

Corresponds to Lean: def WorkflowInstance.is_active

Source

pub fn pending_count(&self) -> usize

Count pending nodes (O(1))

Corresponds to Lean: def WorkflowInstance.pending_count

Source

pub fn active_count(&self) -> usize

Count active nodes (O(1))

Corresponds to Lean: def WorkflowInstance.active_count

Source

pub fn is_terminal(&self) -> bool

Check if all nodes are terminal (completed or failed) (O(1))

Corresponds to Lean: def WorkflowInstance.is_terminal

Source

pub fn has_failure(&self) -> bool

Check if at least one node failed (O(1))

Corresponds to Lean: def WorkflowInstance.has_failure

Source

pub fn status(&self) -> WorkflowStatus

Get the workflow status

Source

pub fn timeout_at(&self) -> Time

Get the timeout deadline

Source

pub fn get_retries(&self, n: u64) -> u64

Get retry count for a node

Source

pub fn definition(&self) -> &WorkflowDef

Get a reference to the definition

Source

pub fn dependencies_satisfied(&self, n: u64) -> bool

Check if dependencies are satisfied for a node

Source

pub fn start_node(&mut self, n: u64) -> Result<(), WorkflowError>

Start a pending node (transition to active)

Returns Err if node not in definition, not pending, or dependencies not satisfied.

§Errors

Returns WorkflowError::NodeNotFound if the node is not in the workflow definition. Returns WorkflowError::InvalidTransition if the node is not in the Pending state. Returns WorkflowError::DependenciesNotSatisfied if upstream nodes are not yet completed.

Source

pub fn complete_node(&mut self, n: u64) -> Result<(), WorkflowError>

Complete an active node (transition to completed)

§Errors

Returns WorkflowError::NodeNotFound if the node is not in the workflow definition. Returns WorkflowError::InvalidTransition if the node is not in the Active state.

Source

pub fn fail_node(&mut self, n: u64) -> Result<(), WorkflowError>

Fail an active node (transition to failed)

§Errors

Returns WorkflowError::NodeNotFound if the node is not in the workflow definition. Returns WorkflowError::InvalidTransition if the node is not in the Active state.

Source

pub fn apply_timeout(&mut self)

Apply timeout

Source

pub fn measure(&self, now: Time) -> u64

Calculate the termination measure

Corresponds to Lean: def workflow_measure

A natural number that decreases on each workflow step.

Trait Implementations§

Source§

impl Clone for WorkflowInstance

Source§

fn clone(&self) -> WorkflowInstance

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 WorkflowInstance

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for WorkflowInstance

Source§

fn default() -> WorkflowInstance

Returns the “default value” for a type. 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, 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> 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 = 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.