From d5f33a9a986f21c8b660eb1d3faa9953f2b8bba7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 14 Nov 2017 23:24:04 +0100 Subject: 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. --- src/jenkins.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src') 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> { +// ) -> Result<(), Box> { +// ) -> 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 { -- cgit v1.2.3