From cfa9547434ea9b7f8666f6f140fc342f73741da9 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 18 Mar 2018 16:05:14 -0400 Subject: [PATCH] Merge the snippet log in to the standard job action logger --- ofborg/src/tasks/build.rs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/ofborg/src/tasks/build.rs b/ofborg/src/tasks/build.rs index 2a96337..d8784de 100644 --- a/ofborg/src/tasks/build.rs +++ b/ofborg/src/tasks/build.rs @@ -55,6 +55,7 @@ pub struct JobActions<'a, 'b> { receiver: &'a mut notifyworker::NotificationReceiver, job: &'b buildjob::BuildJob, line_counter: u64, + snippet_log: VecDeque, attempt_id: String, log_exchange: Option, log_routing_key: Option, @@ -86,6 +87,7 @@ impl<'a, 'b> JobActions<'a, 'b> { receiver: receiver, job: job, line_counter: 0, + snippet_log: VecDeque::with_capacity(10), attempt_id: format!("{}", Uuid::new_v4()), log_exchange: log_exchange, log_routing_key: log_routing_key, @@ -94,6 +96,10 @@ impl<'a, 'b> JobActions<'a, 'b> { }; } + pub fn log_snippet(&self) -> VecDeque { + self.snippet_log.clone() + } + pub fn commit_missing(&mut self) { self.tell(worker::Action::Ack); } @@ -149,9 +155,25 @@ impl<'a, 'b> JobActions<'a, 'b> { )); } + pub fn log_instantiation_errors(&mut self, cannot_build: Vec<(String, Vec)>) { + for (attr, log) in cannot_build { + self.log_line(&format!("Cannot nix-instantiate `{}' because:", &attr)); + + for line in log { + self.log_line(&line); + } + self.log_line(""); + } + } + pub fn log_line(&mut self, line: &str) { self.line_counter += 1; + if self.snippet_log.len() >= 10 { + self.snippet_log.pop_front(); + } + self.snippet_log.push_back(line.to_owned()); + let msg = buildlogmsg::BuildLogMsg { identity: self.identity.clone(), system: self.system.clone(), @@ -340,17 +362,7 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker { let acmd = AsyncCmd::new(cmd); let mut spawned = acmd.spawn(); - let mut snippet_log = VecDeque::with_capacity(10); - - - for line in spawned.lines().iter() { - - if snippet_log.len() >= 10 { - snippet_log.pop_front(); - } - - snippet_log.push_back(line.to_owned()); actions.log_line(&line); } @@ -364,10 +376,10 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker { println!("ok built ({:?}), building", success); println!("Lines:\n-----8<-----"); - snippet_log.iter().inspect(|x| println!("{}", x)).last(); + actions.log_snippet().iter().inspect(|x| println!("{}", x)).last(); println!("----->8-----"); - let last10lines: Vec = snippet_log.into_iter().collect::>(); + let last10lines: Vec = actions.log_snippet().into_iter().collect::>(); actions.build_finished(success, last10lines.clone(), can_build, cannot_build); println!("Done!");