pub trait TaskMiddleware: Send + Sync {
// Required methods
fn before<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
inv_id: &'life1 InvocationId,
task_id: &'life2 TaskId,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn after<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
inv_id: &'life1 InvocationId,
task_id: &'life2 TaskId,
result: &'life3 Result<String, RustvelloError>,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
}Expand description
Hook that runs before and after each task invocation on this runner.
Middlewares are called in registration order (FIFO for before,
LIFO for after). If any before hook returns Err, the task
is not executed and the error is propagated.
§Example
use async_trait::async_trait;
use rustvello_core::middleware::TaskMiddleware;
use rustvello_core::error::{RustvelloError, RustvelloResult};
use rustvello_proto::identifiers::{InvocationId, TaskId};
struct LoggingMiddleware;
#[async_trait]
impl TaskMiddleware for LoggingMiddleware {
async fn before(&self, inv_id: &InvocationId, task_id: &TaskId) -> RustvelloResult<()> {
println!("Starting {} for {}", task_id, inv_id);
Ok(())
}
async fn after(
&self,
inv_id: &InvocationId,
task_id: &TaskId,
result: &Result<String, RustvelloError>,
) -> RustvelloResult<()> {
println!("Finished {} for {}: {}", task_id, inv_id, result.is_ok());
Ok(())
}
}Required Methods§
Sourcefn before<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
inv_id: &'life1 InvocationId,
task_id: &'life2 TaskId,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn before<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
inv_id: &'life1 InvocationId,
task_id: &'life2 TaskId,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called before the task function runs.
Sourcefn after<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
inv_id: &'life1 InvocationId,
task_id: &'life2 TaskId,
result: &'life3 Result<String, RustvelloError>,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn after<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
inv_id: &'life1 InvocationId,
task_id: &'life2 TaskId,
result: &'life3 Result<String, RustvelloError>,
) -> Pin<Box<dyn Future<Output = RustvelloResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Called after the task function runs (regardless of success/failure).