pub struct WorkflowContext { /* private fields */ }Implementations§
Source§impl WorkflowContext
impl WorkflowContext
pub fn message_stream(&self, name: impl Into<String>) -> Result<MessageStream>
Sourcepub fn workflow_identity(&self) -> Result<WorkflowIdentity>
pub fn workflow_identity(&self) -> Result<WorkflowIdentity>
Identity of the parent workflow currently being replayed.
Sourcepub fn history_budget(&self) -> Result<WorkflowHistoryBudget>
pub fn history_budget(&self) -> Result<WorkflowHistoryBudget>
Return the server-published history budget for this workflow task.
Sourcepub fn continue_as_new<T: Serialize>(&self, args: T) -> Result<Value>
pub fn continue_as_new<T: Serialize>(&self, args: T) -> Result<Value>
Continue this workflow instance as a fresh run with replacement arguments.
Return this value directly from the workflow handler. The worker converts it to the terminal protocol command only after replay has consumed every recorded durable command.
Sourcepub fn continue_as_new_with_options<T: Serialize>(
&self,
options: ContinueAsNewOptions,
args: T,
) -> Result<Value>
pub fn continue_as_new_with_options<T: Serialize>( &self, options: ContinueAsNewOptions, args: T, ) -> Result<Value>
Continue as new with optional workflow-type and task-queue overrides.
pub fn activity<T: Serialize>( &self, activity_type: impl Into<String>, args: T, ) -> ActivityCall ⓘ
pub fn activity_on_queue<T, Q>( &self, activity_type: impl Into<String>, task_queue: Option<Q>, args: T, ) -> ActivityCall ⓘ
Sourcepub fn activity_with_options<T: Serialize>(
&self,
activity_type: impl Into<String>,
options: ActivityOptions,
args: T,
) -> ActivityCall ⓘ
pub fn activity_with_options<T: Serialize>( &self, activity_type: impl Into<String>, options: ActivityOptions, args: T, ) -> ActivityCall ⓘ
Schedule one durable activity with retry, routing, and timeout options.
Options are validated before the command is emitted. Once the command is recorded, replay consumes the same activity lifecycle at this command position and never emits a duplicate schedule.
let result = ctx
.activity_with_options(
"charge-card",
ActivityOptions::new()
.task_queue("payments")
.retry_policy(
ActivityRetryPolicy::new(4).exponential_backoff(
Duration::from_secs(1),
2,
Some(Duration::from_secs(30)),
),
)
.start_to_close_timeout(Duration::from_secs(60))
.schedule_to_close_timeout(Duration::from_secs(180))
.heartbeat_timeout(Duration::from_secs(15)),
json!([{"order_id": "order-42"}]),
)
.await;
match result {
Err(Error::ActivityFailed(failure)) => Ok(json!({
"reason": failure.reason,
"timeout_kind": failure.timeout_kind,
})),
other => other,
}pub async fn activity_avro_value<T: Serialize>( &self, activity_type: impl Into<String>, args: T, ) -> Result<AvroValue>
pub async fn activity_avro_value_with_options<T: Serialize>( &self, activity_type: impl Into<String>, options: ActivityOptions, args: T, ) -> Result<AvroValue>
Sourcepub async fn activity_typed<I, O>(
&self,
activity_type: impl Into<String>,
args: I,
) -> Result<O>where
I: Serialize,
O: DeserializeOwned,
pub async fn activity_typed<I, O>(
&self,
activity_type: impl Into<String>,
args: I,
) -> Result<O>where
I: Serialize,
O: DeserializeOwned,
Schedule an activity with a Serde request and decode its Serde result.
Sourcepub async fn activity_typed_with_options<I, O>(
&self,
activity_type: impl Into<String>,
options: ActivityOptions,
args: I,
) -> Result<O>where
I: Serialize,
O: DeserializeOwned,
pub async fn activity_typed_with_options<I, O>(
&self,
activity_type: impl Into<String>,
options: ActivityOptions,
args: I,
) -> Result<O>where
I: Serialize,
O: DeserializeOwned,
Schedule an activity with options and decode its result into O.
Both directions use the fixed Avro Value codec. In particular, this
method does not deserialize the JSON-safe inspection projection returned
by the dynamic ActivityCall future.
Sourcepub fn parallel(&self, operations: Vec<ParallelOperation>) -> ParallelCall ⓘ
pub fn parallel(&self, operations: Vec<ParallelOperation>) -> ParallelCall ⓘ
Schedule and join a deterministic activity/child/timer group.
Nested groups retain their input shape. Every durable leaf is scheduled
before this future yields, results are assembled by declaration order,
and a failure returns Error::ParallelFailed with typed cause,
declaration path, stable group metadata, and completed siblings.
Sourcepub fn join(&self, operations: Vec<ParallelOperation>) -> ParallelCall ⓘ
pub fn join(&self, operations: Vec<ParallelOperation>) -> ParallelCall ⓘ
Alias for WorkflowContext::parallel.
Sourcepub async fn parallel_avro_value(
&self,
operations: Vec<ParallelOperation>,
) -> Result<Vec<ParallelAvroResult>>
pub async fn parallel_avro_value( &self, operations: Vec<ParallelOperation>, ) -> Result<Vec<ParallelAvroResult>>
Lossless fixed-Avro variant of WorkflowContext::parallel.
Sourcepub fn is_cancellation_requested(&self) -> Result<bool>
pub fn is_cancellation_requested(&self) -> Result<bool>
Whether the current workflow task carries a cooperative cancel request.
Sourcepub fn throw_if_cancellation_requested(&self) -> Result<()>
pub fn throw_if_cancellation_requested(&self) -> Result<()>
Raise a typed cooperative cancellation at an author-controlled point.
Passing this result to Saga::finish compensates already registered
forward steps before the cancellation remains the initiating outcome.
pub fn wait_signal(&self, signal_name: impl Into<String>) -> SignalCall ⓘ
pub async fn wait_signal_avro_value( &self, signal_name: impl Into<String>, ) -> Result<Vec<AvroValue>>
Sourcepub fn signals(&self, signal_name: &str) -> Result<Vec<Vec<Value>>>
pub fn signals(&self, signal_name: &str) -> Result<Vec<Vec<Value>>>
Return every committed signal argument list with the given name.
This history-backed view is deterministic and is intended for
condition predicates that must be re-evaluated after a signal while the
workflow is blocked on WorkflowContext::wait_condition.
Sourcepub fn signals_avro_value(
&self,
signal_name: &str,
) -> Result<Vec<Vec<AvroValue>>>
pub fn signals_avro_value( &self, signal_name: &str, ) -> Result<Vec<Vec<AvroValue>>>
Lossless fixed Avro Value view of committed signals with the given name.
Sourcepub fn updates(&self, update_name: &str) -> Result<Vec<Vec<Value>>>
pub fn updates(&self, update_name: &str) -> Result<Vec<Vec<Value>>>
Return every committed update argument list with the given name.
Accepted and applied records for the same update ID are de-duplicated. A Server task created after an update therefore replays the workflow and re-evaluates an open condition without application polling.
Sourcepub fn updates_avro_value(
&self,
update_name: &str,
) -> Result<Vec<Vec<AvroValue>>>
pub fn updates_avro_value( &self, update_name: &str, ) -> Result<Vec<Vec<AvroValue>>>
Lossless fixed Avro Value view of committed updates with the given name.
Sourcepub fn wait_condition<F>(
&self,
options: ConditionWaitOptions,
predicate: F,
) -> ConditionWaitCall ⓘ
pub fn wait_condition<F>( &self, options: ConditionWaitOptions, predicate: F, ) -> ConditionWaitCall ⓘ
Wait for a deterministic predicate to become true or for its durable timeout to elapse.
Prefer wait_condition! for inline predicates so changes to the Rust
predicate tokens automatically change the recorded definition
fingerprint. Direct callers must provide an equally stable identity in
ConditionWaitOptions.
Sourcepub fn sleep(&self, duration: Duration) -> TimerCall ⓘ
pub fn sleep(&self, duration: Duration) -> TimerCall ⓘ
Wait for server-backed durable time without blocking the worker executor.
Polling this future emits one start_timer command and yields. The
server records the deadline, so neither worker nor server restarts reset
the wait. Replay resolves the future only from a TimerScheduled and
TimerFired pair at the same position in the shared durable-command
stream, with matching sequence, timer identity, and delay. Sub-second
durations round up because protocol deadlines use whole seconds.
let mut worker = Worker::new(client, "rust-workers");
worker.register_workflow("delayed-greeting", |ctx, _input| async move {
ctx.sleep(Duration::from_secs(5)).await?;
Ok(json!({"status": "timer fired"}))
});Sourcepub fn start_timer(&self, duration: Duration) -> TimerCall ⓘ
pub fn start_timer(&self, duration: Duration) -> TimerCall ⓘ
Alias for WorkflowContext::sleep for timer-oriented workflow code.
Sourcepub fn side_effect<T, F>(&self, callback: F) -> Result<T>
pub fn side_effect<T, F>(&self, callback: F) -> Result<T>
Evaluate a non-deterministic callback once and durably record its typed value.
On replay the callback is not invoked: the value is decoded from the
sequence-matched SideEffectRecorded event using the workflow’s payload
codec. Use this for UUIDs, wall-clock snapshots, random values, and other
small values that must remain fixed for the lifetime of a workflow run.
Sourcepub fn side_effect_avro_value<F>(&self, callback: F) -> Result<AvroValue>
pub fn side_effect_avro_value<F>(&self, callback: F) -> Result<AvroValue>
Record or replay a lossless fixed Avro Value side effect.
Sourcepub fn append_workflow_stream(
&self,
stream_name: impl Into<String>,
items: &[WorkflowStreamAppendItem],
max_pending_items: Option<u64>,
) -> Result<()>
pub fn append_workflow_stream( &self, stream_name: impl Into<String>, items: &[WorkflowStreamAppendItem], max_pending_items: Option<u64>, ) -> Result<()>
Append output items at a deterministic workflow command boundary.
Stable idempotency keys are derived from the server-provided durable workflow command identity, command ordinal, and item index. Replay consumes the recorded side effect and never emits another append.
Sourcepub fn close_workflow_stream(
&self,
stream_name: impl Into<String>,
retention_seconds: Option<u64>,
) -> Result<()>
pub fn close_workflow_stream( &self, stream_name: impl Into<String>, retention_seconds: Option<u64>, ) -> Result<()>
Close a run-scoped output stream at a deterministic command boundary.
Sourcepub fn error_workflow_stream(
&self,
stream_name: impl Into<String>,
error_reason: impl Into<String>,
retention_seconds: Option<u64>,
) -> Result<()>
pub fn error_workflow_stream( &self, stream_name: impl Into<String>, error_reason: impl Into<String>, retention_seconds: Option<u64>, ) -> Result<()>
Mark a run-scoped output stream errored at a deterministic command boundary.
Sourcepub fn upsert_search_attributes(
&self,
update: SearchAttributeUpdate,
) -> Result<()>
pub fn upsert_search_attributes( &self, update: SearchAttributeUpdate, ) -> Result<()>
Validate, emit, or replay a typed workflow search-attribute update.
The command is non-blocking within a workflow decision, but its
SearchAttributesUpserted event occupies the same deterministic command
stream as activities, timers, conditions, and other durable operations.
Sourcepub fn uuid_v4(&self) -> Result<Uuid>
pub fn uuid_v4(&self) -> Result<Uuid>
Record a UUIDv4 once and return the same UUID on every replay.
Sourcepub fn get_version(
&self,
change_id: impl Into<String>,
min_supported: i32,
max_supported: i32,
) -> Result<i32>
pub fn get_version( &self, change_id: impl Into<String>, min_supported: i32, max_supported: i32, ) -> Result<i32>
Select the newest supported version for a change, or replay the version already committed for that stable change ID.
Sourcepub fn patched(&self, change_id: impl Into<String>) -> Result<bool>
pub fn patched(&self, change_id: impl Into<String>) -> Result<bool>
Record or replay the standard -1 (legacy) / 1 (patched) marker.
Sourcepub fn deprecate_patch(&self, change_id: impl Into<String>) -> Result<()>
pub fn deprecate_patch(&self, change_id: impl Into<String>) -> Result<()>
Keep a patch marker in history after the legacy branch has been removed.
Sourcepub fn upsert_memo<T: Serialize>(&self, entries: T) -> Result<()>
pub fn upsert_memo<T: Serialize>(&self, entries: T) -> Result<()>
Merge non-indexed workflow memo metadata through durable history.
Avro null deletes a key. The SDK encodes the complete patch in the
public Avro payload envelope consumed by Server and Cloud runtimes.
Sourcepub fn start_child_workflow<T: Serialize>(
&self,
workflow_type: impl Into<String>,
options: ChildWorkflowOptions,
args: T,
) -> ChildWorkflowCall ⓘ
pub fn start_child_workflow<T: Serialize>( &self, workflow_type: impl Into<String>, options: ChildWorkflowOptions, args: T, ) -> ChildWorkflowCall ⓘ
Start a named durable child on an explicit queue and await its result.
The command is recorded in the parent’s sequence-ordered durable command
stream. Replay keeps a scheduled child pending without emitting another
start, or consumes its matching terminal ChildRun* outcome. Successful
values preserve the history payload codec and include both sides of the
durable relationship; failures are returned as
Error::ChildWorkflowFailed.
let mut worker = Worker::new(client, "parent-workers");
worker.register_workflow("order-parent", |ctx, _input| async move {
let child = ctx
.start_child_workflow(
"fulfil-order",
ChildWorkflowOptions::new("fulfilment-workers")
.parent_close_policy(ParentClosePolicy::RequestCancel),
json!([{"order_id": "order-42"}]),
)
.await?;
Ok(child.result)
});pub async fn start_child_workflow_avro_value<T: Serialize>( &self, workflow_type: impl Into<String>, options: ChildWorkflowOptions, args: T, ) -> Result<ChildWorkflowAvroResult>
Trait Implementations§
Source§impl Clone for WorkflowContext
impl Clone for WorkflowContext
Source§fn clone(&self) -> WorkflowContext
fn clone(&self) -> WorkflowContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more