Merge the snippet log in to the standard job action logger
This commit is contained in:
parent
789986a1a0
commit
cfa9547434
|
@ -55,6 +55,7 @@ pub struct JobActions<'a, 'b> {
|
||||||
receiver: &'a mut notifyworker::NotificationReceiver,
|
receiver: &'a mut notifyworker::NotificationReceiver,
|
||||||
job: &'b buildjob::BuildJob,
|
job: &'b buildjob::BuildJob,
|
||||||
line_counter: u64,
|
line_counter: u64,
|
||||||
|
snippet_log: VecDeque<String>,
|
||||||
attempt_id: String,
|
attempt_id: String,
|
||||||
log_exchange: Option<String>,
|
log_exchange: Option<String>,
|
||||||
log_routing_key: Option<String>,
|
log_routing_key: Option<String>,
|
||||||
|
@ -86,6 +87,7 @@ impl<'a, 'b> JobActions<'a, 'b> {
|
||||||
receiver: receiver,
|
receiver: receiver,
|
||||||
job: job,
|
job: job,
|
||||||
line_counter: 0,
|
line_counter: 0,
|
||||||
|
snippet_log: VecDeque::with_capacity(10),
|
||||||
attempt_id: format!("{}", Uuid::new_v4()),
|
attempt_id: format!("{}", Uuid::new_v4()),
|
||||||
log_exchange: log_exchange,
|
log_exchange: log_exchange,
|
||||||
log_routing_key: log_routing_key,
|
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) {
|
pub fn commit_missing(&mut self) {
|
||||||
self.tell(worker::Action::Ack);
|
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) {
|
pub fn log_line(&mut self, line: &str) {
|
||||||
self.line_counter += 1;
|
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 {
|
let msg = buildlogmsg::BuildLogMsg {
|
||||||
identity: self.identity.clone(),
|
identity: self.identity.clone(),
|
||||||
system: self.system.clone(),
|
system: self.system.clone(),
|
||||||
|
@ -340,17 +362,7 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
|
||||||
let acmd = AsyncCmd::new(cmd);
|
let acmd = AsyncCmd::new(cmd);
|
||||||
let mut spawned = acmd.spawn();
|
let mut spawned = acmd.spawn();
|
||||||
|
|
||||||
let mut snippet_log = VecDeque::with_capacity(10);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for line in spawned.lines().iter() {
|
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);
|
actions.log_line(&line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,10 +376,10 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
|
||||||
|
|
||||||
println!("ok built ({:?}), building", success);
|
println!("ok built ({:?}), building", success);
|
||||||
println!("Lines:\n-----8<-----");
|
println!("Lines:\n-----8<-----");
|
||||||
snippet_log.iter().inspect(|x| println!("{}", x)).last();
|
actions.log_snippet().iter().inspect(|x| println!("{}", x)).last();
|
||||||
println!("----->8-----");
|
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);
|
actions.build_finished(success, last10lines.clone(), can_build, cannot_build);
|
||||||
println!("Done!");
|
println!("Done!");
|
||||||
|
|
Loading…
Reference in a new issue