summaryrefslogtreecommitdiff
path: root/ofborg/tickborg/src/notifyworker.rs
blob: f83ab04a1a3ab56388a6b2ff49a5c5d8bdce3c3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::sync::Arc;

use crate::worker::Action;

#[async_trait::async_trait]
pub trait SimpleNotifyWorker {
    type J;

    async fn consumer(
        &self,
        job: Self::J,
        notifier: Arc<dyn NotificationReceiver + std::marker::Send + std::marker::Sync>,
    );

    fn msg_to_job(
        &self,
        routing_key: &str,
        content_type: &Option<String>,
        body: &[u8],
    ) -> Result<Self::J, String>;
}

#[async_trait::async_trait]
pub trait NotificationReceiver {
    async fn tell(&self, action: Action);
}

#[derive(Default)]
pub struct DummyNotificationReceiver {
    pub actions: parking_lot::Mutex<Vec<Action>>,
}

impl DummyNotificationReceiver {
    pub fn new() -> DummyNotificationReceiver {
        Default::default()
    }
}

#[async_trait::async_trait]
impl NotificationReceiver for DummyNotificationReceiver {
    async fn tell(&self, action: Action) {
        let mut actions = self.actions.lock();
        actions.push(action);
    }
}