pub trait WorkerInterceptor:
Send
+ Sync
+ 'static {
// Provided methods
fn execute_workflow_task<'a>(
&'a self,
context: &'a WorkflowTaskInterceptorContext,
next: WorkflowTaskNext<'a>,
) -> InterceptorFuture<'a, Result<WorkflowTaskOutcome>> { ... }
fn execute_activity(
&self,
context: ActivityInterceptorContext,
next: ActivityNext,
) -> InterceptorFuture<'_, Result<AvroValue>> { ... }
fn execute_query_task<'a>(
&'a self,
context: &'a QueryTaskInterceptorContext,
next: QueryTaskNext<'a>,
) -> InterceptorFuture<'a, Result<AvroValue, QueryTaskFailure>> { ... }
fn execute_update_validation_task<'a>(
&'a self,
context: &'a UpdateValidationInterceptorContext,
next: UpdateValidationNext<'a>,
) -> InterceptorFuture<'a, Result<UpdateValidationOutcome>> { ... }
}Expand description
Ordered hooks around worker task execution.
Every method defaults to calling next unchanged, so implement only the
hooks you need. Hooks return boxed futures, typically
Box::pin(async move { ... }).
use durable_workflow::interceptors::{
InterceptorFuture, WorkerInterceptor, WorkflowTaskInterceptorContext, WorkflowTaskNext,
WorkflowTaskOutcome,
};
use durable_workflow::Result;
struct AuditLog;
impl WorkerInterceptor for AuditLog {
fn execute_workflow_task<'a>(
&'a self,
context: &'a WorkflowTaskInterceptorContext,
next: WorkflowTaskNext<'a>,
) -> InterceptorFuture<'a, Result<WorkflowTaskOutcome>> {
Box::pin(async move {
let outcome = next.run().await?;
// The commands are always new for this task; a retry has attempt > 1.
println!(
"{} attempt {} produced {} commands",
context.task_id(),
context.attempt(),
outcome.commands().len()
);
Ok(outcome)
})
}
}Provided Methods§
Sourcefn execute_workflow_task<'a>(
&'a self,
context: &'a WorkflowTaskInterceptorContext,
next: WorkflowTaskNext<'a>,
) -> InterceptorFuture<'a, Result<WorkflowTaskOutcome>>
fn execute_workflow_task<'a>( &'a self, context: &'a WorkflowTaskInterceptorContext, next: WorkflowTaskNext<'a>, ) -> InterceptorFuture<'a, Result<WorkflowTaskOutcome>>
Wrap one workflow task. Run next exactly once.
The returned outcome is ignored: the worker settles the core’s own decision. Returning an error after the core succeeded fails the workflow task (not the workflow).
Sourcefn execute_activity(
&self,
context: ActivityInterceptorContext,
next: ActivityNext,
) -> InterceptorFuture<'_, Result<AvroValue>>
fn execute_activity( &self, context: ActivityInterceptorContext, next: ActivityNext, ) -> InterceptorFuture<'_, Result<AvroValue>>
Wrap one activity attempt, remote or local.
Pass the context to next, optionally with transformed arguments
(ActivityInterceptorContext::with_args). The returned value is the
activity result the worker reports, so an interceptor may transform it,
handle an error, or skip next entirely.
Sourcefn execute_query_task<'a>(
&'a self,
context: &'a QueryTaskInterceptorContext,
next: QueryTaskNext<'a>,
) -> InterceptorFuture<'a, Result<AvroValue, QueryTaskFailure>>
fn execute_query_task<'a>( &'a self, context: &'a QueryTaskInterceptorContext, next: QueryTaskNext<'a>, ) -> InterceptorFuture<'a, Result<AvroValue, QueryTaskFailure>>
Wrap one query task. The returned value is what the worker reports.
Sourcefn execute_update_validation_task<'a>(
&'a self,
context: &'a UpdateValidationInterceptorContext,
next: UpdateValidationNext<'a>,
) -> InterceptorFuture<'a, Result<UpdateValidationOutcome>>
fn execute_update_validation_task<'a>( &'a self, context: &'a UpdateValidationInterceptorContext, next: UpdateValidationNext<'a>, ) -> InterceptorFuture<'a, Result<UpdateValidationOutcome>>
Wrap one update-validation task. Run next exactly once.
The returned outcome is ignored: the worker sends the validator’s own
approval or rejection. Returning an error, returning without running
next, or dropping it partway makes the worker report
update_validation_worker_failed, so the update is not accepted.