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
impl WorkflowInstance
Sourcepub fn new(
workflow_def: WorkflowDef,
timeout_at: Time,
max_retries: u64,
) -> Self
pub fn new( workflow_def: WorkflowDef, timeout_at: Time, max_retries: u64, ) -> Self
Create a new workflow instance
Sourcepub fn running(timeout_at: Time) -> Self
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.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if this workflow is running
Convenience method that delegates to status().is_running()
Sourcepub fn get_node_state(&self, n: u64) -> NodeState
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).
Sourcepub fn is_pending(&self, n: u64) -> bool
pub fn is_pending(&self, n: u64) -> bool
Check if node is in pending state
Corresponds to Lean: def WorkflowInstance.is_pending
Sourcepub fn is_active(&self, n: u64) -> bool
pub fn is_active(&self, n: u64) -> bool
Check if node is in active state
Corresponds to Lean: def WorkflowInstance.is_active
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Count pending nodes (O(1))
Corresponds to Lean: def WorkflowInstance.pending_count
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Count active nodes (O(1))
Corresponds to Lean: def WorkflowInstance.active_count
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Check if all nodes are terminal (completed or failed) (O(1))
Corresponds to Lean: def WorkflowInstance.is_terminal
Sourcepub fn has_failure(&self) -> bool
pub fn has_failure(&self) -> bool
Check if at least one node failed (O(1))
Corresponds to Lean: def WorkflowInstance.has_failure
Sourcepub fn status(&self) -> WorkflowStatus
pub fn status(&self) -> WorkflowStatus
Get the workflow status
Sourcepub fn timeout_at(&self) -> Time
pub fn timeout_at(&self) -> Time
Get the timeout deadline
Sourcepub fn get_retries(&self, n: u64) -> u64
pub fn get_retries(&self, n: u64) -> u64
Get retry count for a node
Sourcepub fn definition(&self) -> &WorkflowDef
pub fn definition(&self) -> &WorkflowDef
Get a reference to the definition
Sourcepub fn dependencies_satisfied(&self, n: u64) -> bool
pub fn dependencies_satisfied(&self, n: u64) -> bool
Check if dependencies are satisfied for a node
Sourcepub fn start_node(&mut self, n: u64) -> Result<(), WorkflowError>
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.
Sourcepub fn complete_node(&mut self, n: u64) -> Result<(), WorkflowError>
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.
Sourcepub fn fail_node(&mut self, n: u64) -> Result<(), WorkflowError>
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.
Sourcepub fn apply_timeout(&mut self)
pub fn apply_timeout(&mut self)
Apply timeout
Trait Implementations§
Source§impl Clone for WorkflowInstance
impl Clone for WorkflowInstance
Source§fn clone(&self) -> WorkflowInstance
fn clone(&self) -> WorkflowInstance
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more