pub struct WorkflowContext {
pub workflow_id: String,
pub current_state: String,
pub definition_name: Option<String>,
pub definition_version: Option<String>,
pub data: HashMap<String, Value>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub history: Vec<StateChange>,
pub cursor: Option<WorkflowCursor>,
}Expand description
Workflow execution context.
Persisted between steps so workflows survive process restarts. Each step can read from and write to the context.
Fields§
§workflow_id: StringUnique identifier for this workflow instance
current_state: StringCurrent state name
definition_name: Option<String>Workflow definition name used by this context, when known.
definition_version: Option<String>Workflow definition version used by this context, when known.
data: HashMap<String, Value>Key-value data bag (query results, user inputs, etc.)
created_at: DateTime<Utc>When this workflow instance was created
updated_at: DateTime<Utc>When this context was last updated
history: Vec<StateChange>Audit trail of state transitions
cursor: Option<WorkflowCursor>Cursor used to resume inside nested workflow blocks after a Wait.
Implementations§
Source§impl WorkflowContext
impl WorkflowContext
Sourcepub fn new(
workflow_id: impl Into<String>,
initial_state: impl Into<String>,
) -> Self
pub fn new( workflow_id: impl Into<String>, initial_state: impl Into<String>, ) -> Self
Create a new context for a workflow instance.
Sourcepub fn transition_to(
&mut self,
new_state: impl Into<String>,
reason: Option<String>,
)
pub fn transition_to( &mut self, new_state: impl Into<String>, reason: Option<String>, )
Transition to a new state, recording the change.
Sourcepub fn set_cursor(&mut self, cursor: WorkflowCursor)
pub fn set_cursor(&mut self, cursor: WorkflowCursor)
Store a resume cursor for the next run.
Sourcepub fn take_cursor(&mut self) -> Option<WorkflowCursor>
pub fn take_cursor(&mut self) -> Option<WorkflowCursor>
Remove and return the current resume cursor.
Sourcepub fn clear_cursor(&mut self)
pub fn clear_cursor(&mut self)
Clear any saved resume cursor.
Sourcepub fn transition_count(&self) -> usize
pub fn transition_count(&self) -> usize
Get the number of state transitions that have occurred.