diff options
| author | Teddy Wing | 2017-11-09 22:31:03 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-11-09 22:31:03 +0100 | 
| commit | 7e5c0754be6178ab6ad44a3d3c787f5494065742 (patch) | |
| tree | 1f6a7804c29325271b7eff9cdf9f28597fd49142 /src | |
| parent | 1c97796ad13fdc5d78d44a459be3286e8d79530b (diff) | |
| download | kipper-7e5c0754be6178ab6ad44a3d3c787f5494065742.tar.bz2 | |
`find_and_track_build_and_update_status`: Simplify polling loop
By using a while loop on the status being 'pending', we can get rid of a
level of nesting.
Diffstat (limited to 'src')
| -rw-r--r-- | src/jenkins.rs | 61 | 
1 files changed, 30 insertions, 31 deletions
| diff --git a/src/jenkins.rs b/src/jenkins.rs index b491a75..edfb95f 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -93,8 +93,7 @@ pub fn find_and_track_build_and_update_status(                  // Start timer                  let now = Instant::now(); -                let job_status = job.result; -                let commit_status = job_status.commit_status(); +                let commit_status = job.result.commit_status();                  github::update_commit_status(                      &commit_ref, @@ -104,7 +103,7 @@ pub fn find_and_track_build_and_update_status(                      "continuous-integration/jenkins".to_string()                  ); -                if job_status == JobStatus::Pending { +                while job.result == JobStatus::Pending {                      // loop                      // if timer > 20 minutes                      //   call github::update_commit_status with timeout error @@ -115,35 +114,35 @@ pub fn find_and_track_build_and_update_status(                      //   call github::update_commit_status                      //   stop -                    loop { -                        if now.elapsed().as_secs() == t20_minutes { -                            github::update_commit_status( -                                &commit_ref, -                                &github::CommitStatus::Error, -                                job_url.clone(), -                                Some("The status checker timed out.".to_string()), -                                "continuous-integration/jenkins".to_string() -                            ); - -                            return -                        } - -                        sleep(Duration::from_secs(30)); - -                        let job = request_job(job_url.as_ref()); - -                        if job.result != job_status { -                            github::update_commit_status( -                                &commit_ref, -                                &job.result.commit_status(), -                                job_url.clone(), -                                None, -                                "continuous-integration/jenkins".to_string() -                            ); - -                            return -                        } +                    if now.elapsed().as_secs() == t20_minutes { +                        github::update_commit_status( +                            &commit_ref, +                            &github::CommitStatus::Error, +                            job_url.clone(), +                            Some("The status checker timed out.".to_string()), +                            "continuous-integration/jenkins".to_string() +                        ); + +                        return                      } + +                    sleep(Duration::from_secs(30)); + +                    let updated_job = request_job(job_url.as_ref()); + +                    if job.result != updated_job.result { +                        github::update_commit_status( +                            &commit_ref, +                            &job.result.commit_status(), +                            job_url.clone(), +                            None, +                            "continuous-integration/jenkins".to_string() +                        ); + +                        return +                    } + +                    let job = updated_job;                  }              }); | 
