From f717f7f96288608d7e8f21763bee5629b286e46d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 13 Jan 2018 11:56:05 -0500 Subject: [PATCH] Experiment with ticks via tell --- ofborg/src/bin/test.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/ofborg/src/bin/test.rs b/ofborg/src/bin/test.rs index 5c1ba94..9383531 100644 --- a/ofborg/src/bin/test.rs +++ b/ofborg/src/bin/test.rs @@ -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); }