Skip to main content

WorkflowInterceptor

Trait WorkflowInterceptor 

Source
pub trait WorkflowInterceptor: 'static {
Show 14 methods // Provided methods fn initialize_workflow( &self, _ctx: WorkflowContextView, input: InitializeWorkflowInput, next: WorkflowNext<'_, InitializeWorkflowInput, InitializeWorkflowOutput>, ) -> InitializeWorkflowOutput { ... } fn execute<'a>( &'a self, _ctx: WorkflowInterceptorContext, input: ExecuteWorkflowInput, next: WorkflowNext<'a, ExecuteWorkflowInput, WorkflowInterceptorFuture<'a, Result<Box<dyn WorkflowOutputValue>, WorkflowTermination>>>, ) -> WorkflowInterceptorFuture<'a, Result<Box<dyn WorkflowOutputValue>, WorkflowTermination>> { ... } fn handle_signal<'a>( &'a self, _ctx: WorkflowInterceptorContext, input: HandleSignalInput, next: WorkflowNext<'a, HandleSignalInput, WorkflowInterceptorFuture<'a, Result<(), WorkflowError>>>, ) -> WorkflowInterceptorFuture<'a, Result<(), WorkflowError>> { ... } fn handle_update<'a>( &'a self, _ctx: WorkflowInterceptorContext, input: HandleUpdateInput, next: WorkflowNext<'a, HandleUpdateInput, WorkflowInterceptorFuture<'a, Result<Box<dyn WorkflowOutputValue>, WorkflowError>>>, ) -> WorkflowInterceptorFuture<'a, Result<Box<dyn WorkflowOutputValue>, WorkflowError>> { ... } fn handle_query( &self, _ctx: SyncWorkflowInterceptorContext, input: HandleQueryInput, next: WorkflowNext<'_, HandleQueryInput, Result<Box<dyn WorkflowOutputValue>, WorkflowError>>, ) -> Result<Box<dyn WorkflowOutputValue>, WorkflowError> { ... } fn validate_update( &self, _ctx: SyncWorkflowInterceptorContext, input: ValidateUpdateInput, next: WorkflowNext<'_, ValidateUpdateInput, Result<(), WorkflowError>>, ) -> Result<(), WorkflowError> { ... } fn start_timer( &self, _ctx: WorkflowInterceptorContext, input: StartTimerInput, next: WorkflowNext<'static, StartTimerInput, CancellableWorkflowOutboundFuture<TimerResult>>, ) -> CancellableWorkflowOutboundFuture<TimerResult> { ... } fn schedule_activity( &self, _ctx: WorkflowInterceptorContext, input: ScheduleActivityInput, next: WorkflowNext<'static, ScheduleActivityInput, CancellableWorkflowOutboundFuture<Result<Box<dyn WorkflowOutboundValue>, ActivityExecutionError>>>, ) -> CancellableWorkflowOutboundFuture<Result<Box<dyn WorkflowOutboundValue>, ActivityExecutionError>> { ... } fn schedule_local_activity( &self, _ctx: WorkflowInterceptorContext, input: ScheduleLocalActivityInput, next: WorkflowNext<'static, ScheduleLocalActivityInput, CancellableWorkflowOutboundFuture<Result<Box<dyn WorkflowOutboundValue>, ActivityExecutionError>>>, ) -> CancellableWorkflowOutboundFuture<Result<Box<dyn WorkflowOutboundValue>, ActivityExecutionError>> { ... } fn start_child_workflow( &self, _ctx: WorkflowInterceptorContext, input: StartChildWorkflowInput, next: WorkflowNext<'static, StartChildWorkflowInput, CancellableWorkflowOutboundFuture<Result<StartChildWorkflowOutput, ChildWorkflowStartError>>>, ) -> CancellableWorkflowOutboundFuture<Result<StartChildWorkflowOutput, ChildWorkflowStartError>> { ... } fn signal_workflow( &self, _ctx: WorkflowInterceptorContext, input: SignalWorkflowInput, next: WorkflowNext<'static, SignalWorkflowInput, CancellableWorkflowOutboundFuture<Result<(), WorkflowSignalError>>>, ) -> CancellableWorkflowOutboundFuture<Result<(), WorkflowSignalError>> { ... } fn cancel_external_workflow( &self, _ctx: WorkflowInterceptorContext, input: CancelExternalWorkflowInput, next: WorkflowNext<'static, CancelExternalWorkflowInput, WorkflowOutboundFuture<Result<CancelExternalOk, Failure>>>, ) -> WorkflowOutboundFuture<Result<CancelExternalOk, Failure>> { ... } fn continue_as_new( &self, _ctx: SyncWorkflowInterceptorContext, input: ContinueAsNewInput, next: WorkflowNext<'static, ContinueAsNewInput, Result<Infallible, WorkflowTermination>>, ) -> Result<Infallible, WorkflowTermination> { ... } fn start_nexus_operation( &self, _ctx: WorkflowInterceptorContext, input: StartNexusOperationInput, next: WorkflowNext<'static, StartNexusOperationInput, CancellableWorkflowOutboundFuture<Result<StartedNexusOperation, Failure>>>, ) -> CancellableWorkflowOutboundFuture<Result<StartedNexusOperation, Failure>> { ... }
}
Expand description

Interceptor for calls into workflow code and commands issued by workflow code.

Implement this trait for behavior that should wrap workflow operations. Inbound methods intercept operations such as workflow execution and handler dispatch; outbound methods intercept timers, activities, child workflows, external workflow calls, continue-as-new, and Nexus operations.

Implementations normally calls WorkflowNext::run exactly once. It may transform the input first, then inspect or transform the result. Not calling next short-circuits the operation, so it should only be done if intentionally skipping the operation.

The async inbound methods return WorkflowInterceptorFuture. Use WorkflowInterceptorFuture::new to wrap an async block around the downstream future: call next.run(input).await to call the next interceptor. See the module-level guide for a complete example and the determinism requirements.

Interceptors run as workflow code and are recreated when an evicted workflow is rebuilt. Their behavior and any instance-local state must remain deterministic under replay. Async methods may await only workflow scheduler primitives or SDK-provided workflow futures.

A WorkflowInterceptorConstructor creates one interceptor for each in-memory workflow instance. The same interceptor object handles inbound and outbound calls for that instance and is recreated if the workflow is evicted and rebuilt. Inbound interceptors are called in regsitration order and outbound interceptors are called in reverse order.

Provided Methods§

Source

fn initialize_workflow( &self, _ctx: WorkflowContextView, input: InitializeWorkflowInput, next: WorkflowNext<'_, InitializeWorkflowInput, InitializeWorkflowOutput>, ) -> InitializeWorkflowOutput

Called to invoke the workflow’s #[init] method.

It is only called for workflows that define #[init], before the workflow instance exists.

Source

fn execute<'a>( &'a self, _ctx: WorkflowInterceptorContext, input: ExecuteWorkflowInput, next: WorkflowNext<'a, ExecuteWorkflowInput, WorkflowInterceptorFuture<'a, Result<Box<dyn WorkflowOutputValue>, WorkflowTermination>>>, ) -> WorkflowInterceptorFuture<'a, Result<Box<dyn WorkflowOutputValue>, WorkflowTermination>>

Called to invoke the workflow run method.

Inputs consumed by #[init] are instead passed to WorkflowInterceptor::initialize_workflow.

Source

fn handle_signal<'a>( &'a self, _ctx: WorkflowInterceptorContext, input: HandleSignalInput, next: WorkflowNext<'a, HandleSignalInput, WorkflowInterceptorFuture<'a, Result<(), WorkflowError>>>, ) -> WorkflowInterceptorFuture<'a, Result<(), WorkflowError>>

Called to invoke a signal handler.

Source

fn handle_update<'a>( &'a self, _ctx: WorkflowInterceptorContext, input: HandleUpdateInput, next: WorkflowNext<'a, HandleUpdateInput, WorkflowInterceptorFuture<'a, Result<Box<dyn WorkflowOutputValue>, WorkflowError>>>, ) -> WorkflowInterceptorFuture<'a, Result<Box<dyn WorkflowOutputValue>, WorkflowError>>

Called to invoke an update handler.

Source

fn handle_query( &self, _ctx: SyncWorkflowInterceptorContext, input: HandleQueryInput, next: WorkflowNext<'_, HandleQueryInput, Result<Box<dyn WorkflowOutputValue>, WorkflowError>>, ) -> Result<Box<dyn WorkflowOutputValue>, WorkflowError>

Called to invoke a query handler.

Source

fn validate_update( &self, _ctx: SyncWorkflowInterceptorContext, input: ValidateUpdateInput, next: WorkflowNext<'_, ValidateUpdateInput, Result<(), WorkflowError>>, ) -> Result<(), WorkflowError>

Called to validate an update.

Source

fn start_timer( &self, _ctx: WorkflowInterceptorContext, input: StartTimerInput, next: WorkflowNext<'static, StartTimerInput, CancellableWorkflowOutboundFuture<TimerResult>>, ) -> CancellableWorkflowOutboundFuture<TimerResult>

Called when the workflow starts a timer.

Source

fn schedule_activity( &self, _ctx: WorkflowInterceptorContext, input: ScheduleActivityInput, next: WorkflowNext<'static, ScheduleActivityInput, CancellableWorkflowOutboundFuture<Result<Box<dyn WorkflowOutboundValue>, ActivityExecutionError>>>, ) -> CancellableWorkflowOutboundFuture<Result<Box<dyn WorkflowOutboundValue>, ActivityExecutionError>>

Called when the workflow schedules an activity.

Source

fn schedule_local_activity( &self, _ctx: WorkflowInterceptorContext, input: ScheduleLocalActivityInput, next: WorkflowNext<'static, ScheduleLocalActivityInput, CancellableWorkflowOutboundFuture<Result<Box<dyn WorkflowOutboundValue>, ActivityExecutionError>>>, ) -> CancellableWorkflowOutboundFuture<Result<Box<dyn WorkflowOutboundValue>, ActivityExecutionError>>

Called when the workflow schedules a local activity.

Source

fn start_child_workflow( &self, _ctx: WorkflowInterceptorContext, input: StartChildWorkflowInput, next: WorkflowNext<'static, StartChildWorkflowInput, CancellableWorkflowOutboundFuture<Result<StartChildWorkflowOutput, ChildWorkflowStartError>>>, ) -> CancellableWorkflowOutboundFuture<Result<StartChildWorkflowOutput, ChildWorkflowStartError>>

Called when the workflow starts a child workflow.

Source

fn signal_workflow( &self, _ctx: WorkflowInterceptorContext, input: SignalWorkflowInput, next: WorkflowNext<'static, SignalWorkflowInput, CancellableWorkflowOutboundFuture<Result<(), WorkflowSignalError>>>, ) -> CancellableWorkflowOutboundFuture<Result<(), WorkflowSignalError>>

Called when the workflow signals a child or external workflow.

Source

fn cancel_external_workflow( &self, _ctx: WorkflowInterceptorContext, input: CancelExternalWorkflowInput, next: WorkflowNext<'static, CancelExternalWorkflowInput, WorkflowOutboundFuture<Result<CancelExternalOk, Failure>>>, ) -> WorkflowOutboundFuture<Result<CancelExternalOk, Failure>>

Called when the workflow requests cancellation of an external workflow.

Source

fn continue_as_new( &self, _ctx: SyncWorkflowInterceptorContext, input: ContinueAsNewInput, next: WorkflowNext<'static, ContinueAsNewInput, Result<Infallible, WorkflowTermination>>, ) -> Result<Infallible, WorkflowTermination>

Called when the workflow continues as new.

Source

fn start_nexus_operation( &self, _ctx: WorkflowInterceptorContext, input: StartNexusOperationInput, next: WorkflowNext<'static, StartNexusOperationInput, CancellableWorkflowOutboundFuture<Result<StartedNexusOperation, Failure>>>, ) -> CancellableWorkflowOutboundFuture<Result<StartedNexusOperation, Failure>>

Called when the workflow starts a Nexus operation.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§