diff options
author | Teddy Wing | 2017-11-14 23:24:04 +0100 |
---|---|---|
committer | Teddy Wing | 2017-11-14 23:24:04 +0100 |
commit | d5f33a9a986f21c8b660eb1d3faa9953f2b8bba7 (patch) | |
tree | f0fe2b8ad4ea4e3b681e8cc1ee7fcdd2b33b8575 /src/jenkins.rs | |
parent | df9b4dbd7aa8401b0e488c99c49205bc39dc5a80 (diff) | |
download | kipper-d5f33a9a986f21c8b660eb1d3faa9953f2b8bba7.tar.bz2 |
find_and_track_build_and_update_status(): Try to wrap the fn in a thread
Try to put the whole function inside a thread. This doesn't work because
of move problems. The reason for wrapping things in a thread is so I can
add a `sleep` at the top of the function.
We want to sleep before even making our first request to Jenkins because
it seems like we're making the request too early, before the job has
been created. This prevents the GitHub status from being set.
Diffstat (limited to 'src/jenkins.rs')
-rw-r--r-- | src/jenkins.rs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/jenkins.rs b/src/jenkins.rs index 61d3bf1..d507f00 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -97,17 +97,28 @@ pub fn find_and_track_build_and_update_status( jenkins_user_id: &String, jenkins_token: &String, github_token: String, -) -> Result<(), Box<Error>> { +// ) -> Result<(), Box<Error>> { +// ) -> thread::JoinHandle { +) -> thread::JoinHandle<()> { + thread::spawn(move || { + // Wait for Jenkins to warm up + sleep(Duration::from_secs(10)); + let jenkins_client = jenkins_request_client( &jenkins_user_id, &jenkins_token - )?; + ).expect("Failed to initialise Jenkins HTTP client"); let jobs = get_jobs( &jenkins_url, &jenkins_client, commit_ref.repo.as_ref() - )?; + ).expect( + format!( + "Failed to request Jenkins jobs for {}", + commit_ref.repo + ).as_ref() + ); let t20_minutes = 60 * 20; for job_url in jobs { @@ -115,7 +126,9 @@ pub fn find_and_track_build_and_update_status( &jenkins_url, &jenkins_client, job_url.as_ref() - )?; + ).expect( + format!("Failed to request Jenkins job {}", job_url).as_ref() + ); // Does `displayName` match if job_for_commit(&job, &commit_ref) { @@ -206,11 +219,13 @@ pub fn find_and_track_build_and_update_status( } }); - return Ok(()) + // return Ok(()) + return } } + }) - Ok(()) + // Ok(()) } pub fn auth_credentials(user_id: String, token: String) -> header::Basic { |