Skip to content
Durable Workflowrust

Struct WorkflowEnvironment

Source
pub struct WorkflowEnvironment { /* private fields */ }
Expand description

In-process workflow/activity registration and recorded-history replay.

Implementations§

Source§

impl WorkflowEnvironment

Source

pub fn new() -> Result<Self>

Create an environment without contacting any Server.

Source

pub fn from_worker(worker: Worker) -> Self

Reuse an application’s complete registered workflow/activity set. Execution methods on this environment do not use the Worker’s transport.

Source

pub fn worker_mut(&mut self) -> &mut Worker

Access all existing typed, lossless and replayed-state registration APIs.

Source

pub fn register_workflow<F, Fut>(&mut self, name: impl Into<String>, handler: F)
where F: Fn(WorkflowContext, Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value>> + Send + 'static,

Source

pub fn register_workflow_avro_value<F, Fut>( &mut self, name: impl Into<String>, handler: F, )
where F: Fn(WorkflowContext, AvroValue) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<AvroValue>> + Send + 'static,

Source

pub fn register_activity<F, Fut>(&mut self, name: impl Into<String>, handler: F)
where F: Fn(ActivityContext, Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value>> + Send + 'static,

Source

pub fn register_activity_avro_value<F, Fut>( &mut self, name: impl Into<String>, handler: F, )
where F: Fn(ActivityContext, AvroValue) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<AvroValue>> + Send + 'static,

Source

pub fn mock_activity<F, Fut>(&mut self, name: impl Into<String>, handler: F)
where F: Fn(ActivityContext, Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value>> + Send + 'static,

Explicitly replace an activity callback for this environment, retaining the production Worker’s duplicate-registration checks for real handlers.

Source

pub fn mock_activity_avro_value<F, Fut>( &mut self, name: impl Into<String>, handler: F, )
where F: Fn(ActivityContext, AvroValue) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<AvroValue>> + Send + 'static,

Lossless fixed-Avro counterpart to Self::mock_activity.

Source

pub fn max_steps(self, limit: usize) -> Self

Source

pub fn last_history(&self) -> Option<&WorkflowHistory>

Source

pub fn replay(&self, history: &WorkflowHistory) -> Result<ReplayReport>

Replay through the worker’s codec, durable-command and marker paths. Newly emitted durable commands are divergences, including commands added after the recorded history ended. No activity callbacks are invoked.

Source§

impl WorkflowEnvironment

Source

pub async fn run_activity<T: Serialize>( &self, name: &str, input: T, ) -> Result<Value>

Run one registered activity attempt, including its normal argument/result conversion. Heartbeats are captured locally. This method does not retry; workflow execution applies the workflow’s activity retry policy.

Source

pub async fn run_activity_avro_value( &self, name: &str, input: AvroValue, ) -> Result<AvroValue>

Source

pub async fn run_workflow<T: Serialize>( &mut self, name: &str, input: T, ) -> Result<Value>

Run a new workflow without a Server, returning its result or original typed failure. Each durable turn uses the worker’s cold-replay engine. Activity retry delays and durable timers are skipped. Registered activity handlers run normally and may be replaced by test callbacks.

External services, signals, child workflows, sessions, cancellation and activity timeout simulation require a live integration test; unsupported commands fail explicitly. Parallel activity handlers run in command order.

Source

pub async fn run_workflow_avro_value( &mut self, name: &str, input: AvroValue, ) -> Result<AvroValue>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

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

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

fn with_current_context(self) -> WithContext<Self>

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

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