Skip to main content

Module hooks

Module hooks 

Source
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 execution
  • after_execute: Called after a task completes successfully
  • on_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§

LoggingHooks
Logging hooks that emit tracing events
NoopHooks
Default no-op hooks implementation
TaskHookContext
Context passed to hook callbacks
TaskHookRegistry
Registry for task hooks

Enums§

RetryDecision
Decision returned by on_failure hook

Traits§

TaskHooks
Trait for task execution hooks