From 2ad0edc741e74e73dd22d42334e6f6deb92a128e Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 21 Feb 2018 22:42:52 -0500 Subject: [PATCH] Actually collect metadata in the log collector... --- ofborg/src/tasks/log_message_collector.rs | 28 +++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/ofborg/src/tasks/log_message_collector.rs b/ofborg/src/tasks/log_message_collector.rs index 623c36a..551970e 100644 --- a/ofborg/src/tasks/log_message_collector.rs +++ b/ofborg/src/tasks/log_message_collector.rs @@ -158,20 +158,30 @@ impl worker::SimpleWorker for LogMessageCollector { body: &Vec, ) -> Result { - let decode = serde_json::from_slice(body); - if let Err(e) = decode { - return Err(format!("failed to decode job: {:?}", e)); + let message: Either; + let attempt_id: String; + + let decode_msg: Result = serde_json::from_slice(body); + if let Ok(msg) = decode_msg { + attempt_id = msg.attempt_id.clone(); + message = Right(msg); + } else { + let decode_msg: Result = serde_json::from_slice(body); + if let Ok(msg) = decode_msg { + attempt_id = msg.attempt_id.clone(); + message = Left(msg); + } else { + return Err(format!("failed to decode job: {:?}", decode_msg)); + } } - let message: BuildLogMsg = decode.unwrap(); - - Ok(LogMessage { + return Ok(LogMessage { from: LogFrom { routing_key: deliver.routing_key.clone(), - attempt_id: message.attempt_id.clone(), + attempt_id: attempt_id, }, - message: Right(message), - }) + message: message + }); } fn consumer(&mut self, job: &LogMessage) -> worker::Actions {