diff --git a/ofborg/Cargo.lock b/ofborg/Cargo.lock index 5d7537d..f337772 100644 --- a/ofborg/Cargo.lock +++ b/ofborg/Cargo.lock @@ -14,6 +14,7 @@ dependencies = [ "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -686,6 +687,14 @@ name = "utf8-ranges" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "uuid" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "vcpkg" version = "0.2.2" @@ -817,6 +826,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" "checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" +"checksum uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7cfec50b0842181ba6e713151b72f4ec84a6a7e2c9c8a8a3ffc37bb1cd16b231" "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" diff --git a/ofborg/Cargo.toml b/ofborg/Cargo.toml index 50d320f..ae9fe2b 100644 --- a/ofborg/Cargo.toml +++ b/ofborg/Cargo.toml @@ -9,6 +9,7 @@ env_logger = "0.4.3" # amqp = { path = "./rust-amqp/" } # for testing patches amqp = { git = "https://github.com/grahamc/rust-amqp.git" } md5 = "0.3.5" +uuid = { version = "0.4", features = ["v4"] } fs2 = "0.4.2" serde = "1.0" serde_derive = "1.0" diff --git a/ofborg/src/lib.rs b/ofborg/src/lib.rs index a816f4a..94adcf0 100644 --- a/ofborg/src/lib.rs +++ b/ofborg/src/lib.rs @@ -14,6 +14,7 @@ extern crate tempfile; extern crate amqp; extern crate fs2; extern crate md5; +extern crate uuid; pub mod acl; pub mod checkout; diff --git a/ofborg/src/message/buildlogmsg.rs b/ofborg/src/message/buildlogmsg.rs index 551bdb3..9763a2b 100644 --- a/ofborg/src/message/buildlogmsg.rs +++ b/ofborg/src/message/buildlogmsg.rs @@ -6,4 +6,12 @@ pub struct BuildLogMsg { pub output: String, pub identity: String, pub system: String, + pub attempt_id: String, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct BuildLogStart { + pub identity: String, + pub system: String, + pub attempt_id: String, } diff --git a/ofborg/src/tasks/build.rs b/ofborg/src/tasks/build.rs index c8a1f93..0ffd610 100644 --- a/ofborg/src/tasks/build.rs +++ b/ofborg/src/tasks/build.rs @@ -1,6 +1,9 @@ extern crate amqp; +extern crate uuid; extern crate env_logger; +use uuid::Uuid; + use std::collections::VecDeque; use std::slice::Iter; use std::fs::File; @@ -48,16 +51,18 @@ struct JobActions<'a, 'b> { receiver: &'a mut notifyworker::NotificationReceiver, job: &'b buildjob::BuildJob, line_counter: u64, + attempt_id: String, } impl<'a, 'b> JobActions<'a, 'b> { fn new(system: &str, identity: &str, job: &'b buildjob::BuildJob, receiver: &'a mut notifyworker::NotificationReceiver) -> JobActions<'a, 'b> { return JobActions { system: system.to_owned(), - identity: system.to_owned(), + identity: identity.to_owned(), receiver: receiver, job: job, line_counter: 0, + attempt_id: format!("{}", Uuid::new_v4()), }; } @@ -87,12 +92,29 @@ impl<'a, 'b> JobActions<'a, 'b> { self.tell(worker::Action::Ack); } + pub fn log_started(&mut self) { + self.line_counter += 1; + + let msg = buildlogmsg::BuildLogStart { + identity: self.identity.clone(), + system: self.system.clone(), + attempt_id: self.attempt_id.clone(), + }; + + self.tell(worker::publish_serde_action( + Some("logs".to_owned()), + Some("build.log".to_owned()), + &msg + )); + } + pub fn log_line(&mut self, line: &str) { self.line_counter += 1; let msg = buildlogmsg::BuildLogMsg { identity: self.identity.clone(), system: self.system.clone(), + attempt_id: self.attempt_id.clone(), line_number: self.line_counter, output: line.to_owned(), }; @@ -194,6 +216,7 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker { job.attrs.clone() ); + actions.log_started(); let acmd = AsyncCmd::new(cmd); let mut spawned = acmd.spawn();