jenkins: retry when Jenkins doesn't give us a build URL
diff mbox

Message ID 20161122031901.9312-1-andrew.donnellan@au1.ibm.com
State Accepted
Headers show

Commit Message

Andrew Donnellan Nov. 22, 2016, 3:19 a.m. UTC
From: Russell Currey <ruscur@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@russell.cc>
[ajd: rework the logic and commit message]
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 src/jenkins.rs | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Comments

Andrew Donnellan Nov. 22, 2016, 4:05 a.m. UTC | #1
On 22/11/16 14:19, Andrew Donnellan wrote:
> From: Russell Currey <ruscur@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@russell.cc>
> [ajd: rework the logic and commit message]
> Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

Applied to master: 3b2e30c742ccede3a7a36f1ea199fad80bbd5372

Patch
diff mbox

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)),
+            }
         }
     }