[snowpatch] [PATCH] jenkins: retry when Jenkins doesn't give us a build URL
Andrew Donnellan
andrew.donnellan at au1.ibm.com
Tue Nov 22 14:19:01 AEDT 2016
From: Russell Currey <ruscur at russell.cc>
Sometimes when we try to get the build URL, Jenkins isn't ready yet and
responds without details of the "executable". Rather than panic, retry
every 5 seconds until we get something we can use back.
Like other loops in the code, we need to have a timeout eventually.
Signed-off-by: Russell Currey <ruscur at russell.cc>
[ajd: rework the logic and commit message]
Signed-off-by: Andrew Donnellan <andrew.donnellan at au1.ibm.com>
---
src/jenkins.rs | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/jenkins.rs b/src/jenkins.rs
index 0a0a699..6b92a85 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -114,9 +114,19 @@ impl JenkinsBackend {
}
pub fn get_build_url(&self, build_queue_entry: &str) -> Option<String> {
- match self.get_api_json_object(build_queue_entry).get("executable") {
- Some(exec) => Some(exec.as_object().unwrap().get("url").unwrap().as_string().unwrap().to_string()),
- None => None
+ loop {
+ let entry = self.get_api_json_object(build_queue_entry);
+ match entry.get("executable") {
+ Some(exec) => return Some(exec
+ .as_object() // Option<BTreeMap>
+ .unwrap() // BTreeMap
+ .get("url") // Option<&str> ?
+ .unwrap() // &str ?
+ .as_string()
+ .unwrap()
+ .to_string()),
+ None => sleep(Duration::from_millis(JENKINS_POLLING_INTERVAL)),
+ }
}
}
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan at au1.ibm.com IBM Australia Limited
More information about the snowpatch
mailing list