Skip to main content

taskgraph/core/
events.rs

1//! Event hooks and observability for taskgraph-rs.
2//! Fully compatible with `no_std`.
3
4/// Event types emitted during task lifecycle.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum TaskEvent {
7    Started,
8    Completed,
9    Failed,
10    Retrying(u32),
11}
12
13/// Trait for observers that want to react to task events.
14pub trait TaskSubscriber: Send + Sync {
15    /// Called when a task event occurs.
16    fn on_event(&self, task_name: &'static str, event: TaskEvent);
17}
18
19/// A simple log subscriber that prints to stdout (std only).
20#[cfg(feature = "std")]
21pub struct ConsoleSubscriber;
22
23#[cfg(feature = "std")]
24impl TaskSubscriber for ConsoleSubscriber {
25    fn on_event(&self, task_name: &'static str, event: TaskEvent) {
26        match event {
27            TaskEvent::Started => println!("[INFO] Task '{}' started", task_name),
28            TaskEvent::Completed => println!("[SUCCESS] Task '{}' finished", task_name),
29            TaskEvent::Failed => println!("[ERROR] Task '{}' failed", task_name),
30            TaskEvent::Retrying(count) => println!("[WARN] Task '{}' retrying (attempt {})", task_name, count),
31        }
32    }
33}