Struct WorkflowContext

Source
pub struct WorkflowContext { /* private fields */ }

Implementations§

Source§

impl WorkflowContext

Source

pub fn message_stream(&self, name: impl Into<String>) -> Result<MessageStream>

Source

pub fn workflow_identity(&self) -> Result<WorkflowIdentity>

Identity of the parent workflow currently being replayed.

Source

pub fn history_budget(&self) -> Result<WorkflowHistoryBudget>

Return the server-published history budget for this workflow task.

Source

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.

Source

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.

Source

pub fn activity<T: Serialize>( &self, activity_type: impl Into<String>, args: T, ) -> ActivityCall

Source

pub fn activity_on_queue<T, Q>( &self, activity_type: impl Into<String>, task_queue: Option<Q>, args: T, ) -> ActivityCall
where T: Serialize, Q: Into<String>,

Source

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,
}
Source

pub async fn activity_avro_value<T: Serialize>( &self, activity_type: impl Into<String>, args: T, ) -> Result<AvroValue>

Source

pub async fn activity_avro_value_with_options<T: Serialize>( &self, activity_type: impl Into<String>, options: ActivityOptions, args: T, ) -> Result<AvroValue>

Source

pub async fn activity_typed<I, O>( &self, activity_type: impl Into<String>, args: I, ) -> Result<O>

Schedule an activity with a Serde request and decode its Serde result.

Source

pub async fn activity_typed_with_options<I, O>( &self, activity_type: impl Into<String>, options: ActivityOptions, args: I, ) -> Result<O>

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.

Source

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.

Source

pub fn join(&self, operations: Vec<ParallelOperation>) -> ParallelCall

Source

pub async fn parallel_avro_value( &self, operations: Vec<ParallelOperation>, ) -> Result<Vec<ParallelAvroResult>>

Lossless fixed-Avro variant of WorkflowContext::parallel.

Source

pub fn saga(&self) -> Saga

Create a workflow-local deterministic compensation registry.

Source

pub fn is_cancellation_requested(&self) -> Result<bool>

Whether the current workflow task carries a cooperative cancel request.

Source

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.

Source

pub fn wait_signal(&self, signal_name: impl Into<String>) -> SignalCall

Source

pub async fn wait_signal_avro_value( &self, signal_name: impl Into<String>, ) -> Result<Vec<AvroValue>>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn wait_condition<F>( &self, options: ConditionWaitOptions, predicate: F, ) -> ConditionWaitCall
where F: Fn() -> Result<bool> + Send + 'static,

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.

Source

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"}))
});
Source

pub fn start_timer(&self, duration: Duration) -> TimerCall

Alias for WorkflowContext::sleep for timer-oriented workflow code.

Source

pub fn side_effect<T, F>(&self, callback: F) -> Result<T>
where T: Serialize + DeserializeOwned, F: FnOnce() -> 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.

Source

pub fn side_effect_avro_value<F>(&self, callback: F) -> Result<AvroValue>
where F: FnOnce() -> AvroValue,

Record or replay a lossless fixed Avro Value side effect.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn uuid_v4(&self) -> Result<Uuid>

Record a UUIDv4 once and return the same UUID on every replay.

Source

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.

Source

pub fn patched(&self, change_id: impl Into<String>) -> Result<bool>

Record or replay the standard -1 (legacy) / 1 (patched) marker.

Source

pub fn deprecate_patch(&self, change_id: impl Into<String>) -> Result<()>

Keep a patch marker in history after the legacy branch has been removed.

Source

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.

Source

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)
});
Source

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

Source§

fn clone(&self) -> WorkflowContext

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WorkflowContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,