Merge the snippet log in to the standard job action logger

This commit is contained in:
Graham Christensen 2018-03-18 16:05:14 -04:00
parent 789986a1a0
commit cfa9547434
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C

View file

@ -55,6 +55,7 @@ pub struct JobActions<'a, 'b> {
receiver: &'a mut notifyworker::NotificationReceiver,
job: &'b buildjob::BuildJob,
line_counter: u64,
snippet_log: VecDeque<String>,
attempt_id: String,
log_exchange: Option<String>,
log_routing_key: Option<String>,
@ -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<String> {
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<String>)>) {
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<String> = snippet_log.into_iter().collect::<Vec<String>>();
let last10lines: Vec<String> = actions.log_snippet().into_iter().collect::<Vec<String>>();
actions.build_finished(success, last10lines.clone(), can_build, cannot_build);
println!("Done!");