pub enum FlowState {
Created,
Validated,
Instantiated,
Running,
Draining,
Completed,
Cancelled,
Failed,
}Expand description
Flow lifecycle state machine.
Per Doc 04, Section 10.1: 8 states with defined legal transitions.
This is the label-only version in torvyn-types. The reactor crate
provides an extended version with associated data (stats, error info).
State transition diagram:
Created -> Validated -> Instantiated -> Running -> Draining -> Completed
Created -> Failed -> Cancelled
Validated -> Failed -> Failed
Running -> Draining -> Failed§Examples
use torvyn_types::FlowState;
let state = FlowState::Created;
assert!(state.can_transition_to(&FlowState::Validated));
assert!(!state.can_transition_to(&FlowState::Running));
let new_state = state.transition_to(FlowState::Validated).unwrap();
assert_eq!(new_state, FlowState::Validated);Variants§
Created
Flow definition has been submitted but not yet validated.
Validated
Contracts and capabilities have been validated.
Instantiated
Components have been instantiated and streams are connected.
Running
The flow is actively processing stream elements.
Draining
The flow is draining remaining elements after a completion or cancellation signal.
Completed
The flow completed successfully.
Cancelled
The flow was cancelled by operator or policy.
Failed
The flow failed due to an unrecoverable error.
Implementations§
Source§impl FlowState
impl FlowState
Sourcepub fn can_transition_to(&self, target: &FlowState) -> bool
pub fn can_transition_to(&self, target: &FlowState) -> bool
Returns true if transitioning from self to target is legal.
Legal transitions (per Doc 04, Section 10.2):
- Created -> Validated | Failed
- Validated -> Instantiated | Failed
- Instantiated -> Running
- Running -> Draining
- Draining -> Completed | Cancelled | Failed
§WARM PATH — called per flow state change.
Sourcepub fn transition_to(
self,
target: FlowState,
) -> Result<FlowState, InvalidTransition>
pub fn transition_to( self, target: FlowState, ) -> Result<FlowState, InvalidTransition>
Attempt to transition from self to target.
Returns Ok(target) if the transition is legal, or
Err(InvalidTransition) if it is not.
§WARM PATH — called per flow state change.
Sourcepub const fn is_terminal(&self) -> bool
pub const fn is_terminal(&self) -> bool
Returns true if this state is terminal (no further transitions possible).