Skip to main content

edda_conductor/runner/
notify.rs

1/// Notification interface for plan events.
2#[async_trait::async_trait]
3pub trait Notifier: Send + Sync {
4    async fn notify(&self, message: &str);
5}
6
7/// Prints to stdout.
8pub struct StdoutNotifier;
9
10#[async_trait::async_trait]
11impl Notifier for StdoutNotifier {
12    async fn notify(&self, message: &str) {
13        println!("[conductor] {message}");
14    }
15}
16
17/// Collects messages in memory (for testing).
18pub struct CollectNotifier {
19    messages: std::sync::Mutex<Vec<String>>,
20}
21
22impl Default for CollectNotifier {
23    fn default() -> Self {
24        Self::new()
25    }
26}
27
28impl CollectNotifier {
29    pub fn new() -> Self {
30        Self {
31            messages: std::sync::Mutex::new(Vec::new()),
32        }
33    }
34
35    pub fn messages(&self) -> Vec<String> {
36        self.messages.lock().unwrap().clone()
37    }
38}
39
40#[async_trait::async_trait]
41impl Notifier for CollectNotifier {
42    async fn notify(&self, message: &str) {
43        self.messages.lock().unwrap().push(message.to_string());
44    }
45}