pub struct WorkflowContext<'a> { /* private fields */ }Expand description
Replay helper for Rust workflow runtimes.
WorkflowContext is a read-only view over a workflow invocation. It provides
deterministic helpers for inspecting persisted history and returning the
next command to the engine.
Implementations§
Source§impl<'a> WorkflowContext<'a>
impl<'a> WorkflowContext<'a>
Sourcepub fn new(invocation: &'a WorkflowInvocation) -> Self
pub fn new(invocation: &'a WorkflowInvocation) -> Self
Creates a replay context over one immutable runtime invocation.
Sourcepub fn spec(&self) -> &WorkflowSpec
pub fn spec(&self) -> &WorkflowSpec
Return the immutable workflow definition pinned by run_created.
Sourcepub fn has_patch_marker(&self, patch_id: &str) -> bool
pub fn has_patch_marker(&self, patch_id: &str) -> bool
Return whether this run was created with a replay-safe patch marker.
Marker presence never changes for an existing run. A compatible runtime can therefore keep both code paths and deterministically replay old unmarked histories alongside new marked histories.
Sourcepub fn input_as<T>(&self) -> Result<T>where
T: DeserializeOwned,
pub fn input_as<T>(&self) -> Result<T>where
T: DeserializeOwned,
Decode the workflow input into a host-defined serde type.
Sourcepub fn history(&self) -> &[FlowEventEnvelope]
pub fn history(&self) -> &[FlowEventEnvelope]
Returns committed history in ascending event-sequence order.
Sourcepub fn cancellation_request(&self) -> Option<&CancellationRequest>
pub fn cancellation_request(&self) -> Option<&CancellationRequest>
Return the durable cleanup-aware cancellation request, when present.
Sourcepub fn progress(&self, progress_id: &str) -> Option<&WorkflowProgress>
pub fn progress(&self, progress_id: &str) -> Option<&WorkflowProgress>
Return a durable progress update by its idempotency identity.
Sourcepub fn child_operation(
&self,
reference_id: &str,
) -> Option<&ChildOperationReference>
pub fn child_operation( &self, reference_id: &str, ) -> Option<&ChildOperationReference>
Return a durable child-operation reference by its parent-local id.
Sourcepub fn child_workflow_run_id(&self, child_id: &str) -> Option<&str>
pub fn child_workflow_run_id(&self, child_id: &str) -> Option<&str>
Return the engine-generated root run ID for a durable child request.
Sourcepub fn child_workflow_outcome(
&self,
child_id: &str,
) -> Option<&WorkflowTerminalOutcome>
pub fn child_workflow_outcome( &self, child_id: &str, ) -> Option<&WorkflowTerminalOutcome>
Return the terminal outcome durably observed for a child workflow.
Sourcepub fn signal(&self, signal_id: &str) -> Option<&WorkflowSignal>
pub fn signal(&self, signal_id: &str) -> Option<&WorkflowSignal>
Return a received signal by its caller-owned delivery identity.
Sourcepub fn signal_payload(&self, wait_id: &str) -> Option<&JsonValue>
pub fn signal_payload(&self, wait_id: &str) -> Option<&JsonValue>
Return the payload paired with a completed deterministic signal wait.
Sourcepub fn signal_payload_as<T>(&self, wait_id: &str) -> Result<Option<T>>where
T: DeserializeOwned,
pub fn signal_payload_as<T>(&self, wait_id: &str) -> Result<Option<T>>where
T: DeserializeOwned,
Decode the payload paired with a completed deterministic signal wait.
Sourcepub fn step_output(&self, step_id: &str) -> Option<&JsonValue>
pub fn step_output(&self, step_id: &str) -> Option<&JsonValue>
Returns the durable JSON output of a completed step.
Sourcepub fn step_output_as<T>(&self, step_id: &str) -> Result<Option<T>>where
T: DeserializeOwned,
pub fn step_output_as<T>(&self, step_id: &str) -> Result<Option<T>>where
T: DeserializeOwned,
Decodes a completed step output into a host-defined serde type.
Sourcepub fn step_completed(&self, step_id: &str) -> bool
pub fn step_completed(&self, step_id: &str) -> bool
Returns whether the step has a durable successful output.
Sourcepub fn step_failed(&self, step_id: &str) -> Option<&str>
pub fn step_failed(&self, step_id: &str) -> Option<&str>
Returns the terminal error of a step that exhausted its retries.
Sourcepub fn wait_completed(&self, wait_id: &str) -> bool
pub fn wait_completed(&self, wait_id: &str) -> bool
Returns whether a durable timer wait has completed.
Sourcepub fn hook_payload(&self, hook_id: &str) -> Option<&JsonValue>
pub fn hook_payload(&self, hook_id: &str) -> Option<&JsonValue>
Returns the durable JSON payload received by a hook.
Sourcepub fn hook_payload_as<T>(&self, hook_id: &str) -> Result<Option<T>>where
T: DeserializeOwned,
pub fn hook_payload_as<T>(&self, hook_id: &str) -> Result<Option<T>>where
T: DeserializeOwned,
Decodes a received hook payload into a host-defined serde type.
Sourcepub fn hook_disposed(&self, hook_id: &str) -> bool
pub fn hook_disposed(&self, hook_id: &str) -> bool
Returns whether a hook was explicitly closed without a payload.
Sourcepub fn complete(&self, output: JsonValue) -> RuntimeCommand
pub fn complete(&self, output: JsonValue) -> RuntimeCommand
Returns a command that completes the workflow successfully.
Sourcepub fn fail(&self, error: impl Into<String>) -> RuntimeCommand
pub fn fail(&self, error: impl Into<String>) -> RuntimeCommand
Returns a command that fails the workflow.
Sourcepub fn cancel(&self) -> RuntimeCommand
pub fn cancel(&self) -> RuntimeCommand
Finish a previously requested cancellation after cleanup is durable.
Sourcepub fn timeout(
&self,
deadline: DateTime<Utc>,
reason: Option<String>,
) -> RuntimeCommand
pub fn timeout( &self, deadline: DateTime<Utc>, reason: Option<String>, ) -> RuntimeCommand
Finish a run with a typed timeout outcome.
Sourcepub fn continue_as_new(&self, input: JsonValue) -> RuntimeCommand
pub fn continue_as_new(&self, input: JsonValue) -> RuntimeCommand
Close this history segment and continue with fresh history and input.
The engine persists the successor identity before creating it and
carries the exact current WorkflowSpec into the new run.
Sourcepub fn record_progress(&self, progress: WorkflowProgress) -> RuntimeCommand
pub fn record_progress(&self, progress: WorkflowProgress) -> RuntimeCommand
Persist an idempotently identified progress update and replay.
Sourcepub fn link_child_operation(
&self,
child: ChildOperationReference,
) -> RuntimeCommand
pub fn link_child_operation( &self, child: ChildOperationReference, ) -> RuntimeCommand
Persist a child-operation reference and replay.
Sourcepub fn start_child_workflow(
&self,
child_id: impl Into<String>,
spec: WorkflowSpec,
input: JsonValue,
) -> RuntimeCommand
pub fn start_child_workflow( &self, child_id: impl Into<String>, spec: WorkflowSpec, input: JsonValue, ) -> RuntimeCommand
Start or await a first-class child workflow.
The child ID is stable within this parent history. By default, a parent cancellation request is propagated to an open child and the parent waits for the child’s terminal outcome.
Sourcepub fn start_child_workflow_with_policy(
&self,
child_id: impl Into<String>,
spec: WorkflowSpec,
input: JsonValue,
cancellation_policy: ChildWorkflowCancellationPolicy,
) -> RuntimeCommand
pub fn start_child_workflow_with_policy( &self, child_id: impl Into<String>, spec: WorkflowSpec, input: JsonValue, cancellation_policy: ChildWorkflowCancellationPolicy, ) -> RuntimeCommand
Start or await a child with an explicit cancellation policy.
Sourcepub fn child_workflow(
&self,
child_id: impl Into<String>,
spec: WorkflowSpec,
input: JsonValue,
) -> ChildWorkflowCommand
pub fn child_workflow( &self, child_id: impl Into<String>, spec: WorkflowSpec, input: JsonValue, ) -> ChildWorkflowCommand
Create a child definition for a bounded durable batch.
Sourcepub fn child_workflow_with_policy(
&self,
child_id: impl Into<String>,
spec: WorkflowSpec,
input: JsonValue,
cancellation_policy: ChildWorkflowCancellationPolicy,
) -> ChildWorkflowCommand
pub fn child_workflow_with_policy( &self, child_id: impl Into<String>, spec: WorkflowSpec, input: JsonValue, cancellation_policy: ChildWorkflowCancellationPolicy, ) -> ChildWorkflowCommand
Create a batch child definition with an explicit cancellation policy.
Sourcepub fn start_child_workflows(
&self,
children: Vec<ChildWorkflowCommand>,
) -> RuntimeCommand
pub fn start_child_workflows( &self, children: Vec<ChildWorkflowCommand>, ) -> RuntimeCommand
Durably request a deterministic batch before any child starts.
Sourcepub fn schedule_step(
&self,
step_id: impl Into<String>,
step_name: impl Into<String>,
input: JsonValue,
) -> RuntimeCommand
pub fn schedule_step( &self, step_id: impl Into<String>, step_name: impl Into<String>, input: JsonValue, ) -> RuntimeCommand
Schedules one durable step with the default retry policy.
Sourcepub fn schedule_step_with_retry(
&self,
step_id: impl Into<String>,
step_name: impl Into<String>,
input: JsonValue,
retry: RetryPolicy,
) -> RuntimeCommand
pub fn schedule_step_with_retry( &self, step_id: impl Into<String>, step_name: impl Into<String>, input: JsonValue, retry: RetryPolicy, ) -> RuntimeCommand
Schedules one durable step with an explicit retry policy.
Sourcepub fn step(
&self,
step_id: impl Into<String>,
step_name: impl Into<String>,
input: JsonValue,
) -> StepCommand
pub fn step( &self, step_id: impl Into<String>, step_name: impl Into<String>, input: JsonValue, ) -> StepCommand
Creates a step definition with the default retry policy.
Sourcepub fn step_with_retry(
&self,
step_id: impl Into<String>,
step_name: impl Into<String>,
input: JsonValue,
retry: RetryPolicy,
) -> StepCommand
pub fn step_with_retry( &self, step_id: impl Into<String>, step_name: impl Into<String>, input: JsonValue, retry: RetryPolicy, ) -> StepCommand
Creates a step definition with an explicit retry policy.
Sourcepub fn schedule_steps(&self, steps: Vec<StepCommand>) -> RuntimeCommand
pub fn schedule_steps(&self, steps: Vec<StepCommand>) -> RuntimeCommand
Atomically schedules a deterministic batch of durable steps.
Sourcepub fn wait_until(
&self,
wait_id: impl Into<String>,
resume_at: DateTime<Utc>,
) -> RuntimeCommand
pub fn wait_until( &self, wait_id: impl Into<String>, resume_at: DateTime<Utc>, ) -> RuntimeCommand
Suspends replay until the given UTC deadline becomes ready.
Sourcepub fn create_hook(
&self,
hook_id: impl Into<String>,
token: impl Into<String>,
metadata: JsonValue,
) -> RuntimeCommand
pub fn create_hook( &self, hook_id: impl Into<String>, token: impl Into<String>, metadata: JsonValue, ) -> RuntimeCommand
Creates an externally completable hook with JSON metadata.
Sourcepub fn create_hook_with_metadata(
&self,
hook_id: impl Into<String>,
token: impl Into<String>,
metadata: HookMetadata,
) -> Result<RuntimeCommand>
pub fn create_hook_with_metadata( &self, hook_id: impl Into<String>, token: impl Into<String>, metadata: HookMetadata, ) -> Result<RuntimeCommand>
Creates an externally completable hook with typed metadata.
Sourcepub fn wait_for_signal(
&self,
wait_id: impl Into<String>,
signal_name: impl Into<String>,
) -> RuntimeCommand
pub fn wait_for_signal( &self, wait_id: impl Into<String>, signal_name: impl Into<String>, ) -> RuntimeCommand
Suspend until the next queued signal with signal_name is paired with
the stable wait_id.