Available on crate feature
tasks only.Expand description
Task execution hooks — lifecycle callbacks for task execution
Hooks allow custom behavior to be injected at key points in the task lifecycle:
before_execute: Called before a task starts executionafter_execute: Called after a task completes successfullyon_failure: Called when a task fails, can control retry behavior
§Example
use async_trait::async_trait;
use echo_orchestration::tasks::{RetryDecision, TaskHookContext, TaskHooks};
struct LoggingHooks;
#[async_trait]
impl TaskHooks for LoggingHooks {
async fn before_execute(&self, ctx: &TaskHookContext) {
println!("Starting task: {}", ctx.task.subject);
}
async fn after_execute(&self, ctx: &TaskHookContext, result: &str) {
println!("Completed task: {} -> {}", ctx.task.subject, result);
}
async fn on_failure(&self, ctx: &TaskHookContext, error: &str) -> RetryDecision {
if ctx.task.retry_count < ctx.task.max_retries {
RetryDecision::Retry { delay_secs: 1 }
} else {
RetryDecision::Fail
}
}
}
let _ = LoggingHooks;Structs§
- Logging
Hooks - Logging hooks that emit tracing events
- Noop
Hooks - Default no-op hooks implementation
- Task
Hook Context - Context passed to hook callbacks
- Task
Hook Registry - Registry for task hooks
Enums§
- Retry
Decision - Decision returned by
on_failurehook
Traits§
- Task
Hooks - Trait for task execution hooks