Skip to content
Durable Workflowrust

Module interceptors

Source
Expand description

Ordered worker interceptors around workflow tasks, activities, queries and update validations.

Register interceptors with Worker::interceptor or Worker::interceptors. The first registered interceptor is the outermost wrapper: it runs first before the core and last after it. Each hook receives a context and a next handle; running next continues the chain and the innermost next runs the SDK’s real handling. Every hook has a passthrough default, so an interceptor implements only the hooks it needs.

Workflow-task interceptors cannot change what the workflow records. The core always runs the task as received (WorkflowTaskNext::run takes no input) and the worker submits exactly the commands the core produced. The outcome an interceptor sees is a read-only view. If the core fails, the worker reports that failure even when an interceptor returns Ok. If an interceptor fails after the core succeeded, or returns without running next, the worker fails the workflow task (Error::WorkflowTaskInterceptor); nothing is recorded and the Server retries the task. Interceptors run on every workflow task. WorkflowTaskInterceptorContext::replay_state says whether the task first re-ran a committed history prefix; the worker never resubmits replayed commands, so an outcome’s commands are always new for that task. A failed task’s retry can repeat an outcome; use WorkflowTaskInterceptorContext::attempt to detect retries.

Update-validation interceptors observe a validator’s decision and cannot change it. The validator always runs on the task as received (UpdateValidationNext::run takes no input) and the worker sends the validator’s own approval or rejection. If an interceptor fails, returns without running next, or drops the validation partway, the worker reports update_validation_worker_failed instead: the update is not accepted, and the caller’s retry with the same request id asks the validator again.

Built-in ExecutionTelemetry stays outermost: its spans wrap the whole interceptor chain.

Structs§

ActivityInterceptorContext
Context of one activity attempt; owns the arguments passed down the chain.
ActivityNext
Continues an activity chain; the innermost next runs the activity.
PassthroughWorkerInterceptor
An interceptor that only calls next; a base for partial interceptors.
QueryTaskFailure
A query task failure the worker reports to the Server.
QueryTaskInterceptorContext
Read-only context of one query task.
QueryTaskNext
Continues a query chain; the innermost next answers the query.
UpdateValidationInterceptorContext
Read-only context of one update-validation task.
UpdateValidationNext
Continues an update-validation chain; the innermost next runs the validator.
UpdateValidationOutcome
A read-only view of the decision the validator produced.
WorkflowTaskFailure
A read-only description of the workflow-task core’s own error.
WorkflowTaskInterceptorContext
Read-only context of one workflow task.
WorkflowTaskNext
Continues a workflow-task chain; the innermost next runs the task.
WorkflowTaskOutcome
A read-only view of what the workflow-task core produced.

Traits§

WorkerInterceptor
Ordered hooks around worker task execution.

Type Aliases§

InterceptorFuture
The boxed Send future an interceptor hook returns.