Experiment with ticks via tell

This commit is contained in:
Graham Christensen 2018-01-13 11:56:05 -05:00
parent 0923e45ef8
commit f717f7f962
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C

View file

@ -31,7 +31,6 @@ use ofborg::commentparser;
use amqp::protocol::basic::{Deliver,BasicProperties};
pub struct TestWorker {
system: String,
identity: String,
@ -44,6 +43,28 @@ impl TestWorker {
identity: identity,
};
}
pub fn tick(event: str) -> worker::Action {
worker::Action::Publish(worker::QueueMsg{
exchange: Some(String::from("stats")),
routing_key: None,
content: String::from(event).into_bytes(),
immediate: false,
mandatory: false,
properties: None,
})
}
pub fn say_hi() -> worker::Action {
worker::Action::Publish(worker::QueueMsg{
exchange: None,
routing_key: Some(String::from("test-notify-worker")),
content: String::from("hi").into_bytes(),
immediate: false,
mandatory: false,
properties: None,
})
}
}
impl notifyworker::SimpleNotifyWorker for TestWorker {
@ -58,16 +79,12 @@ impl notifyworker::SimpleNotifyWorker for TestWorker {
fn consumer(&self, job: &String, notifier: &mut notifyworker::NotificationReceiver) {
info!("Working on {}", job);
notifier.tell(self.tick("started-work"));
for i in 1..100 {
notifier.tell(worker::Action::Publish(worker::QueueMsg{
exchange: None,
routing_key: Some(String::from("test-notify-worker")),
content: String::from("hi").into_bytes(),
immediate: false,
mandatory: false,
properties: None,
}));
notifier.tell(self.say_hi());
}
notifier.tell(self.tick("finished-work-success"));
notifier.tell(self.tick("finished-work-failed"));
notifier.tell(worker::Action::Ack);
}