From 2d3b362513d7e256f6a1ed3bdeed2eb785302ff3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 9 Nov 2017 00:25:34 +0100 Subject: jenkins.rs: Start `thread` idea in main function Use `thread::spawn` and update the GitHub commit status. Write an outline for how to handle polling for changes and updating the GitHub commit status on success or failure (or timeout). --- src/jenkins.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/jenkins.rs b/src/jenkins.rs index 42fe6e4..d87c508 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -25,6 +25,8 @@ extern crate mockito; extern crate reqwest; extern crate url; +use std::thread; + use self::reqwest::header::{Authorization, Basic}; use self::url::Url; @@ -65,12 +67,35 @@ pub fn find_and_track_build_and_update_status(commit_ref) { let jobs = get_jobs(); for job_url in jobs { - let payload = request_job(job_url); + let job = request_job(job_url); // Does `displayName` match - if job_for_commit(payload, commit_ref) { - // spawn thread - let status = result_from_job(payload); + if job_for_commit(job, commit_ref) { + thread::spawn(|| { + // Start timer + + github::update_commit_status( + commit_ref, + job.commit_status().result, + job_url, + None, + "continuous-integration/jenkins".to_string() + ); + + if job.result == JobStatus::Pending { + // loop + // if timer > 20 minutes + // call github::update_commit_status with timeout error + // return + // wait 30 seconds + // call request_job again + // if the status is different + // call github::update_commit_status + // stop + } + }); + + return } } } -- cgit v1.2.3