From 9c78ec2db5d86fec473d837d66b3caad33301758 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 11 Nov 2017 09:38:31 -0500 Subject: [PATCH] improve some logging --- mass-rebuilder.php | 2 +- ofborg/Cargo.lock | 1 + ofborg/Cargo.toml | 1 + ofborg/src/clone.rs | 44 ++++++++++++++++++++++++++++++++++++++------ ofborg/src/lib.rs | 3 +++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/mass-rebuilder.php b/mass-rebuilder.php index f9bbd3a..b57d268 100644 --- a/mass-rebuilder.php +++ b/mass-rebuilder.php @@ -162,7 +162,7 @@ function try_eval($ghclient, $owner, $name, $sha, $eval_name, $cmd, $args) { $status->success("Finished running $cmd"); } catch (GHE\ExecException $e) { echo "Failed to run $eval_name on $sha\n"; - $status->pending("Failed to run $cmd"); + $status->failure("Failed to run $cmd"); return false; } } diff --git a/ofborg/Cargo.lock b/ofborg/Cargo.lock index 3a97b90..4f65f0c 100644 --- a/ofborg/Cargo.lock +++ b/ofborg/Cargo.lock @@ -5,6 +5,7 @@ dependencies = [ "amqp 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "fs2 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "md5 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ofborg/Cargo.toml b/ofborg/Cargo.toml index 6434eeb..e7e9cdd 100644 --- a/ofborg/Cargo.toml +++ b/ofborg/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Graham Christensen "] [dependencies] +log = "0.3.8" env_logger = "0.4.3" amqp = "0.1.0" md5 = "0.3.5" diff --git a/ofborg/src/clone.rs b/ofborg/src/clone.rs index d583536..59525cc 100644 --- a/ofborg/src/clone.rs +++ b/ofborg/src/clone.rs @@ -23,21 +23,48 @@ pub trait GitClonable { fn lock_path(&self) -> PathBuf; fn lock(&self) -> Result { - println!("Locking {:?}", self.lock_path()); - let lock = fs::File::create(self.lock_path())?; - lock.lock_exclusive()?; - return Ok(Lock{ - lock: Some(lock) - }) + info!("Locking {:?}", self.lock_path()); + + match fs::File::create(self.lock_path()) { + Err(e) => { + warn!("Failed to create lock file {:?}: {}", + self.lock_path(), e + ); + return Err(e); + } + Ok(lock) => { + match lock.lock_exclusive() { + Err(e) => { + warn!("Failed to get exclusive lock on file {:?}: {}", + self.lock_path(), e + ); + return Err(e); + } + Ok(_) => { + debug!("Got lock on {:?}", self.lock_path()); + return Ok(Lock{ + lock: Some(lock) + }); + } + } + } + + } } fn clone_repo(&self) -> Result<(), Error> { let mut lock = self.lock()?; if self.clone_to().is_dir() { + debug!("Found dir at {:?}, initial clone is done", + self.clone_to()); return Ok(()) } + info!("Initial cloning of {} to {:?}", + self.clone_from(), + self.clone_to()); + let result = Command::new("git") .arg("clone") .args(self.extra_clone_args()) @@ -57,6 +84,7 @@ pub trait GitClonable { fn fetch_repo(&self) -> Result<(), Error> { let mut lock = self.lock()?; + info!("Fetching from origin in {:?}", self.clone_to()); let result = Command::new("git") .arg("fetch") .arg("origin") @@ -75,18 +103,21 @@ pub trait GitClonable { fn clean(&self) -> Result<(), Error> { let mut lock = self.lock()?; + info!("git am --abort"); Command::new("git") .arg("am") .arg("--abort") .current_dir(self.clone_to()) .status()?; + info!("git merge --abort"); Command::new("git") .arg("merge") .arg("--abort") .current_dir(self.clone_to()) .status()?; + info!("git reset --hard"); Command::new("git") .arg("reset") .arg("--hard") @@ -101,6 +132,7 @@ pub trait GitClonable { fn checkout(&self, git_ref: &OsStr) -> Result<(), Error> { let mut lock = self.lock()?; + let result = Command::new("git") .arg("checkout") .arg(git_ref) diff --git a/ofborg/src/lib.rs b/ofborg/src/lib.rs index 0fa5e4e..4ca8488 100644 --- a/ofborg/src/lib.rs +++ b/ofborg/src/lib.rs @@ -3,6 +3,9 @@ extern crate serde_derive; extern crate serde; extern crate serde_json; +#[macro_use] +extern crate log; + extern crate tempfile; extern crate amqp; extern crate fs2;