Merge pull request #108 from NixOS/record-build-status

Record build status - 0.1.3
This commit is contained in:
Graham Christensen 2018-03-10 19:03:44 -05:00 committed by GitHub
commit f1f92d3643
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 19 deletions

View file

@ -45,7 +45,7 @@ let kernel = buildPlatform.parsed.kernel.name;
) [] (builtins.attrNames feat); ) [] (builtins.attrNames feat);
in in
rec { rec {
ofborg = f: ofborg_0_1_2 { features = ofborg_0_1_2_features { ofborg_0_1_2 = f; }; }; ofborg = f: ofborg_0_1_3 { features = ofborg_0_1_3_features { ofborg_0_1_3 = f; }; };
aho_corasick_0_5_3_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate { aho_corasick_0_5_3_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
crateName = "aho-corasick"; crateName = "aho-corasick";
version = "0.5.3"; version = "0.5.3";

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ofborg" name = "ofborg"
version = "0.1.2" version = "0.1.3"
authors = ["Graham Christensen <graham@grahamc.com>"] authors = ["Graham Christensen <graham@grahamc.com>"]
include = ["Cargo.toml", "Cargo.lock", "src", "test-srcs", "build.rs"] include = ["Cargo.toml", "Cargo.lock", "src", "test-srcs", "build.rs"]
build = "build.rs" build = "build.rs"

View file

@ -189,12 +189,20 @@ impl<'a, 'b> JobActions<'a, 'b> {
let result_exchange = self.result_exchange.clone(); let result_exchange = self.result_exchange.clone();
let result_routing_key = self.result_routing_key.clone(); let result_routing_key = self.result_routing_key.clone();
self.tell(worker::publish_serde_action( self.tell(worker::publish_serde_action(
result_exchange, result_exchange,
result_routing_key, result_routing_key,
&msg, &msg,
)); ));
let log_exchange = self.log_exchange.clone();
let log_routing_key = self.log_routing_key.clone();
self.tell(worker::publish_serde_action(
log_exchange,
log_routing_key,
&msg,
));
self.tell(worker::Action::Ack); self.tell(worker::Action::Ack);
} }
@ -216,12 +224,20 @@ impl<'a, 'b> JobActions<'a, 'b> {
let result_exchange = self.result_exchange.clone(); let result_exchange = self.result_exchange.clone();
let result_routing_key = self.result_routing_key.clone(); let result_routing_key = self.result_routing_key.clone();
self.tell(worker::publish_serde_action( self.tell(worker::publish_serde_action(
result_exchange, result_exchange,
result_routing_key, result_routing_key,
&msg, &msg,
)); ));
let log_exchange = self.log_exchange.clone();
let log_routing_key = self.log_routing_key.clone();
self.tell(worker::publish_serde_action(
log_exchange,
log_routing_key,
&msg,
));
self.tell(worker::Action::Ack); self.tell(worker::Action::Ack);
} }
@ -476,7 +492,8 @@ mod tests {
assert_contains_job(&mut actions, "output\":\"2"); assert_contains_job(&mut actions, "output\":\"2");
assert_contains_job(&mut actions, "output\":\"3"); assert_contains_job(&mut actions, "output\":\"3");
assert_contains_job(&mut actions, "output\":\"4"); assert_contains_job(&mut actions, "output\":\"4");
assert_contains_job(&mut actions, "success\":true"); assert_contains_job(&mut actions, "success\":true"); // First one to the github poster
assert_contains_job(&mut actions, "success\":true"); // This one to the logs
assert_eq!(actions.next(), Some(worker::Action::Ack)); assert_eq!(actions.next(), Some(worker::Action::Ack));
} }
@ -517,7 +534,8 @@ mod tests {
println!("Total actions: {:?}", dummyreceiver.actions.len()); println!("Total actions: {:?}", dummyreceiver.actions.len());
let mut actions = dummyreceiver.actions.into_iter(); let mut actions = dummyreceiver.actions.into_iter();
assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // First one to the github poster
assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // This one to the logs
assert_eq!(actions.next(), Some(worker::Action::Ack)); assert_eq!(actions.next(), Some(worker::Action::Ack));
} }
} }

View file

@ -1,7 +1,6 @@
extern crate amqp; extern crate amqp;
extern crate env_logger; extern crate env_logger;
use either::{Either, Left, Right};
use lru_cache::LruCache; use lru_cache::LruCache;
use serde_json; use serde_json;
use std::fs; use std::fs;
@ -11,6 +10,7 @@ use std::io::Write;
use ofborg::writetoline::LineWriter; use ofborg::writetoline::LineWriter;
use ofborg::message::buildlogmsg::{BuildLogStart, BuildLogMsg}; use ofborg::message::buildlogmsg::{BuildLogStart, BuildLogMsg};
use ofborg::message::buildresult::BuildResult;
use ofborg::worker; use ofborg::worker;
use amqp::protocol::basic::{Deliver, BasicProperties}; use amqp::protocol::basic::{Deliver, BasicProperties};
@ -25,10 +25,17 @@ pub struct LogMessageCollector {
log_root: PathBuf, log_root: PathBuf,
} }
#[derive(Debug)]
enum MsgType {
Start(BuildLogStart),
Msg(BuildLogMsg),
Finish(BuildResult),
}
#[derive(Debug)] #[derive(Debug)]
pub struct LogMessage { pub struct LogMessage {
from: LogFrom, from: LogFrom,
message: Either<BuildLogStart, BuildLogMsg>, message: MsgType
} }
fn validate_path_segment(segment: &PathBuf) -> Result<(), String> { fn validate_path_segment(segment: &PathBuf) -> Result<(), String> {
@ -158,20 +165,26 @@ impl worker::SimpleWorker for LogMessageCollector {
body: &Vec<u8>, body: &Vec<u8>,
) -> Result<Self::J, String> { ) -> Result<Self::J, String> {
let message: Either<BuildLogStart, BuildLogMsg>; let message: MsgType;
let attempt_id: String; let attempt_id: String;
let decode_msg: Result<BuildLogMsg, _> = serde_json::from_slice(body); let decode_msg: Result<BuildLogMsg, _> = serde_json::from_slice(body);
if let Ok(msg) = decode_msg { if let Ok(msg) = decode_msg {
attempt_id = msg.attempt_id.clone(); attempt_id = msg.attempt_id.clone();
message = Right(msg); message = MsgType::Msg(msg);
} else { } else {
let decode_msg: Result<BuildLogStart, _> = serde_json::from_slice(body); let decode_msg: Result<BuildLogStart, _> = serde_json::from_slice(body);
if let Ok(msg) = decode_msg { if let Ok(msg) = decode_msg {
attempt_id = msg.attempt_id.clone(); attempt_id = msg.attempt_id.clone();
message = Left(msg); message = MsgType::Start(msg);
} else { } else {
return Err(format!("failed to decode job: {:?}", decode_msg)); let decode_msg: Result<BuildResult, _> = serde_json::from_slice(body);
if let Ok(msg) = decode_msg {
attempt_id = msg.attempt_id.clone();
message = MsgType::Finish(msg);
} else {
return Err(format!("failed to decode job: {:?}", decode_msg));
}
} }
} }
@ -186,15 +199,17 @@ impl worker::SimpleWorker for LogMessageCollector {
fn consumer(&mut self, job: &LogMessage) -> worker::Actions { fn consumer(&mut self, job: &LogMessage) -> worker::Actions {
match job.message { match job.message {
Left(ref start) => { MsgType::Start(ref start) => {
self.write_metadata(&job.from, &start).expect("failed to write metadata"); self.write_metadata(&job.from, &start).expect("failed to write metadata");
}, },
Right(ref message) => { MsgType::Msg(ref message) => {
let handle = self.handle_for(&job.from).unwrap(); let handle = self.handle_for(&job.from).unwrap();
handle.write_to_line((message.line_number - 1) as usize, handle.write_to_line((message.line_number - 1) as usize,
&message.output); &message.output);
} },
MsgType::Finish(ref _finish) => {
},
} }
return vec![worker::Action::Ack]; return vec![worker::Action::Ack];
@ -330,7 +345,7 @@ mod tests {
}; };
let mut job = LogMessage { let mut job = LogMessage {
from: make_from("foo"), from: make_from("foo"),
message: Right(logmsg.clone()), message: MsgType::Msg(logmsg.clone()),
}; };
let p = TestScratch::new_dir("log-message-collector-path_for_log"); let p = TestScratch::new_dir("log-message-collector-path_for_log");
@ -341,7 +356,7 @@ mod tests {
worker.consumer(& worker.consumer(&
LogMessage { LogMessage {
from: make_from("foo"), from: make_from("foo"),
message: Left(BuildLogStart { message: MsgType::Start(BuildLogStart {
attempt_id: String::from("my-attempt-id"), attempt_id: String::from("my-attempt-id"),
identity: String::from("my-identity"), identity: String::from("my-identity"),
system: String::from("foobar-x8664"), system: String::from("foobar-x8664"),
@ -356,14 +371,14 @@ mod tests {
logmsg.line_number = 5; logmsg.line_number = 5;
logmsg.output = String::from("line-5"); logmsg.output = String::from("line-5");
job.message = Right(logmsg.clone()); job.message = MsgType::Msg(logmsg.clone());
assert_eq!(vec![worker::Action::Ack], worker.consumer(&job)); assert_eq!(vec![worker::Action::Ack], worker.consumer(&job));
job.from.attempt_id = String::from("my-other-attempt"); job.from.attempt_id = String::from("my-other-attempt");
logmsg.attempt_id = String::from("my-other-attempt"); logmsg.attempt_id = String::from("my-other-attempt");
logmsg.line_number = 3; logmsg.line_number = 3;
logmsg.output = String::from("line-3"); logmsg.output = String::from("line-3");
job.message = Right(logmsg.clone()); job.message = MsgType::Msg(logmsg.clone());
assert_eq!(vec![worker::Action::Ack], worker.consumer(&job)); assert_eq!(vec![worker::Action::Ack], worker.consumer(&job));
} }