Skip to main content

WorkflowContext

Struct WorkflowContext 

Source
pub struct WorkflowContext<W> { /* private fields */ }
Expand description

Used within workflows to issue commands, get info, etc.

The type parameter W represents the workflow type. This enables type-safe access to workflow state via state_mut() for mutations.

Implementations§

Source§

impl<W> WorkflowContext<W>

Source

pub fn namespace(&self) -> &str

Return the namespace the workflow is executing in

Source

pub fn task_queue(&self) -> &str

Return the task queue the workflow is executing in

Source

pub fn workflow_time(&self) -> Option<SystemTime>

Return the current time according to the workflow (which is not wall-clock time).

Source

pub fn history_length(&self) -> u32

Return the length of history so far at this point in the workflow

Source

pub fn current_deployment_version(&self) -> Option<WorkerDeploymentVersion>

Return the deployment version, if any, as it was when this point in the workflow was first reached. If this code is being executed for the first time, return this Worker’s deployment version if it has one.

Source

pub fn search_attributes(&self) -> impl Deref<Target = SearchAttributes> + '_

Return current values for workflow search attributes

Source

pub fn random_seed(&self) -> u64

Return the workflow’s randomness seed

Source

pub fn is_replaying(&self) -> bool

Returns true if the current workflow task is happening under replay

Source

pub fn headers(&self) -> &HashMap<String, Payload>

Returns the headers for the current handler invocation (signal, update, query, etc.).

Source

pub fn payload_converter(&self) -> &PayloadConverter

Returns the PayloadConverter currently used by the worker running this workflow.

Source

pub fn workflow_initial_info(&self) -> &InitializeWorkflow

Return various information that the workflow was initialized with.

Source

pub async fn cancelled(&self) -> String

A future that resolves if/when the workflow is cancelled, with the user provided cause

Source

pub fn timer<T: Into<TimerOptions>>( &self, opts: T, ) -> impl CancellableFuture<TimerResult>

Request to create a timer

Source

pub fn start_activity<AD: ActivityDefinition>( &self, activity: AD, input: impl Into<AD::Input>, opts: ActivityOptions, ) -> impl CancellableFuture<Result<AD::Output, ActivityExecutionError>>

Request to run an activity

Source

pub fn start_local_activity<AD: ActivityDefinition>( &self, activity: AD, input: impl Into<AD::Input>, opts: LocalActivityOptions, ) -> impl CancellableFuture<Result<AD::Output, ActivityExecutionError>>

Request to run a local activity

Source

pub fn child_workflow(&self, opts: ChildWorkflowOptions) -> ChildWorkflow

Creates a child workflow stub with the provided options

Source

pub fn patched(&self, patch_id: &str) -> bool

Check (or record) that this workflow history was created with the provided patch

Source

pub fn deprecate_patch(&self, patch_id: &str) -> bool

Record that this workflow history was created with the provided patch, and it is being phased out.

Source

pub fn signal_workflow( &self, opts: impl Into<SignalWorkflowOptions>, ) -> impl CancellableFuture<SignalExternalWfResult>

Send a signal to an external workflow.

Source

pub fn upsert_search_attributes( &self, attr_iter: impl IntoIterator<Item = (String, Payload)>, )

Add or create a set of search attributes

Source

pub fn upsert_memo( &self, attr_iter: impl IntoIterator<Item = (String, Payload)>, )

Add or create a set of memo fields

Source

pub fn force_task_fail(&self, with: Error)

Force a workflow task failure (EX: in order to retry on non-sticky queue)

Source

pub fn cancel_external( &self, target: NamespacedWorkflowExecution, reason: String, ) -> impl Future<Output = CancelExternalWfResult>

Request the cancellation of an external workflow.

Source

pub fn start_nexus_operation( &self, opts: NexusOperationOptions, ) -> impl CancellableFuture<Result<StartedNexusOperation, Failure>>

Start a nexus operation

Source

pub fn state<R>(&self, f: impl FnOnce(&W) -> R) -> R

Access workflow state immutably via closure.

The borrow is scoped to the closure and cannot escape, preventing borrows from being held across await points.

Source

pub fn state_mut<R>(&self, f: impl FnOnce(&mut W) -> R) -> R

Access workflow state mutably via closure.

The borrow is scoped to the closure and cannot escape, preventing borrows from being held across await points.

After the mutation, all wakers registered by pending wait_condition futures are woken so that waker-based combinators (e.g. FuturesOrdered) re-poll them on the next pass.

Source

pub fn wait_condition<'a>( &'a self, condition: impl FnMut(&W) -> bool + 'a, ) -> impl Future<Output = ()> + 'a

Wait for some condition on workflow state to become true, yielding the workflow if not.

The condition closure receives an immutable reference to the workflow state, which is borrowed only for the duration of each poll (not across await points).

Trait Implementations§

Source§

impl<W> Clone for WorkflowContext<W>

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<W> Freeze for WorkflowContext<W>

§

impl<W> !RefUnwindSafe for WorkflowContext<W>

§

impl<W> !Send for WorkflowContext<W>

§

impl<W> !Sync for WorkflowContext<W>

§

impl<W> Unpin for WorkflowContext<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for WorkflowContext<W>

§

impl<W> !UnwindSafe for WorkflowContext<W>

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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

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, dest: *mut u8)

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

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

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

Source§

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
Source§

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> 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,