diff options
author | Teddy Wing | 2017-11-14 23:46:27 +0100 |
---|---|---|
committer | Teddy Wing | 2017-11-14 23:46:27 +0100 |
commit | f9b13604484fa7924efb8cde0dd26de0276065ff (patch) | |
tree | c30b02f2fdade2465f5a6756ad6dde44ca1af62a /src/main.rs | |
parent | d5f33a9a986f21c8b660eb1d3faa9953f2b8bba7 (diff) | |
download | kipper-f9b13604484fa7924efb8cde0dd26de0276065ff.tar.bz2 |
find_and_track_build_and_update_status(): Move thread outside function
Instead of wrapping the inside of the function in a thread, put the
thread on the outside, in `main()`. This is an effort to try to get
around the `move`/lifetime issues I was having with the previous
version.
Add some extra logging so we have a better idea what's going on when.
Remove the `expects` I had added and put the `Result` returns back.
In `main()`, wrap the call to `find_and_track_build_and_update_status()`
in a thread and sleep before calling it. This allows us to give Jenkins
some time to warm up and create a job for our commit before we go ahead
and try to request it from its API. Otherwise, if we kick off the
Jenkins fetch too soon, our statuses aren't going to get updated because
the job won't have been created and thus won't have been found on the
`get_jobs()` call.
Had to add some ugly `clone()`s to get around `move` compiler errors
here. Next step is figuring out how to clean that up.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs index 05ca775..c93d616 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,9 @@ extern crate rouille; extern crate kipper; use std::env; +use std::thread; use std::io::Read; +use std::time::Duration; use getopts::Options; @@ -137,20 +139,30 @@ fn main() { }, }; - match jenkins::find_and_track_build_and_update_status( - commit_ref, - jenkins_url.clone(), - &jenkins_user_id, - &jenkins_token, - github_token.clone(), - ) { - Ok(_) => {}, - Err(e) => { - error!("{}", e.to_string()); - - return internal_server_error() - }, - }; + // TODO: Get rid of clones + let jenkins_url = jenkins_url.clone(); + let jenkins_user_id = jenkins_user_id.clone(); + let jenkins_token = jenkins_token.clone(); + let github_token = github_token.clone(); + + thread::spawn(move || { + thread::sleep(Duration::from_secs(30)); + + match jenkins::find_and_track_build_and_update_status( + commit_ref, + &jenkins_url, + &jenkins_user_id, + &jenkins_token, + &github_token, + ) { + Ok(_) => {}, + Err(e) => { + error!("{}", e.to_string()); + + // return internal_server_error() + }, + }; + }); rouille::Response::text("202 Accepted") .with_status_code(202) |