aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jenkins.rs183
-rw-r--r--src/main.rs16
2 files changed, 93 insertions, 106 deletions
diff --git a/src/jenkins.rs b/src/jenkins.rs
index 5c43cd9..860c4ca 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -92,21 +92,11 @@ impl Job {
pub fn find_and_track_build_and_update_status(
commit_ref: CommitRef,
- // jenkins_url: String,
- // jenkins_user_id: &String,
- // jenkins_token: &String,
- // github_token: String,
- jenkins_url: &str,
- jenkins_user_id: &str,
- jenkins_token: &str,
- github_token: &str,
+ jenkins_url: String,
+ jenkins_user_id: &String,
+ jenkins_token: &String,
+ github_token: String,
) -> Result<(), Box<Error>> {
- // TODO: Remove this, rest should take same type as arguments maybe
- let jenkins_url = jenkins_url.to_owned();
- let jenkins_user_id = &jenkins_user_id.to_owned();
- let jenkins_token = &jenkins_token.to_owned();
- let github_token = github_token.to_owned();
-
let jenkins_client = jenkins_request_client(
&jenkins_user_id,
&jenkins_token
@@ -120,7 +110,7 @@ pub fn find_and_track_build_and_update_status(
let t20_minutes = 60 * 20;
for job_url in jobs {
- info!("Looking for job: {}", job_url);
+ debug!("Looking for job: {}", job_url);
let mut job = request_job(
&jenkins_url,
@@ -130,95 +120,94 @@ pub fn find_and_track_build_and_update_status(
// Does `displayName` match
if job_for_commit(&job, &commit_ref) {
- info!("Job found: {}", job_url);
- // thread::spawn(move || {
- // Start timer
- let now = Instant::now();
-
- let commit_status = job.result.commit_status();
-
- github::update_commit_status(
- &github_token,
- &commit_ref,
- &commit_status,
- job_url.clone(),
- None,
- "continuous-integration/jenkins".to_owned()
- ).expect(
- format!(
- "GitHub pending status update failed for {}/{} {}.",
- commit_ref.owner,
- commit_ref.repo,
- commit_ref.sha
- ).as_ref()
- );
+ debug!("Job found: {}", job_url);
+
+ // Start timer
+ let now = Instant::now();
+
+ let commit_status = job.result.commit_status();
+
+ github::update_commit_status(
+ &github_token,
+ &commit_ref,
+ &commit_status,
+ job_url.clone(),
+ None,
+ "continuous-integration/jenkins".to_owned()
+ ).expect(
+ format!(
+ "GitHub pending status update failed for {}/{} {}.",
+ commit_ref.owner,
+ commit_ref.repo,
+ commit_ref.sha
+ ).as_ref()
+ );
+
+ while 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
+
+ debug!("Waiting for job to finish");
+
+ if now.elapsed().as_secs() == t20_minutes {
+ github::update_commit_status(
+ &github_token,
+ &commit_ref,
+ &github::CommitStatus::Error,
+ job_url.clone(),
+ Some("The status checker timed out.".to_owned()),
+ "continuous-integration/jenkins".to_owned()
+ ).expect(
+ format!(
+ "GitHub timeout error status update failed for {}/{} {}.",
+ commit_ref.owner,
+ commit_ref.repo,
+ commit_ref.sha
+ ).as_ref()
+ );
- while 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
-
- info!("Waiting for job to finish");
-
- if now.elapsed().as_secs() == t20_minutes {
- github::update_commit_status(
- &github_token,
- &commit_ref,
- &github::CommitStatus::Error,
- job_url.clone(),
- Some("The status checker timed out.".to_owned()),
- "continuous-integration/jenkins".to_owned()
- ).expect(
- format!(
- "GitHub timeout error status update failed for {}/{} {}.",
- commit_ref.owner,
- commit_ref.repo,
- commit_ref.sha
- ).as_ref()
- );
-
- return Ok(())
- }
+ return Ok(())
+ }
- sleep(Duration::from_secs(30));
+ sleep(Duration::from_secs(30));
- let updated_job = request_job(
- &jenkins_url,
- &jenkins_client,
- job_url.as_ref()
+ let updated_job = request_job(
+ &jenkins_url,
+ &jenkins_client,
+ job_url.as_ref()
+ ).expect(
+ format!("Failed to request job '{}'.", job_url).as_ref()
+ );
+
+ if job.result != updated_job.result {
+ github::update_commit_status(
+ &github_token,
+ &commit_ref,
+ &updated_job.result.commit_status(),
+ job_url.clone(),
+ None,
+ "continuous-integration/jenkins".to_owned()
).expect(
- format!("Failed to request job '{}'.", job_url).as_ref()
+ format!(
+ "GitHub status update failed for {}/{} {}.",
+ commit_ref.owner,
+ commit_ref.repo,
+ commit_ref.sha
+ ).as_ref()
);
- if job.result != updated_job.result {
- github::update_commit_status(
- &github_token,
- &commit_ref,
- &updated_job.result.commit_status(),
- job_url.clone(),
- None,
- "continuous-integration/jenkins".to_owned()
- ).expect(
- format!(
- "GitHub status update failed for {}/{} {}.",
- commit_ref.owner,
- commit_ref.repo,
- commit_ref.sha
- ).as_ref()
- );
-
- return Ok(())
- }
-
- job = updated_job;
+ return Ok(())
}
- // });
+
+ job = updated_job;
+ }
return Ok(())
}
diff --git a/src/main.rs b/src/main.rs
index c93d616..c7be3ee 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -113,7 +113,7 @@ fn main() {
stderrlog::new()
.module(module_path!())
.timestamp(stderrlog::Timestamp::Second)
- .verbosity(4) // LogLevel::Trace
+ .verbosity(2) // LogLevel::Info
.init()
.expect("Logger failed to initialise");
@@ -139,7 +139,9 @@ fn main() {
},
};
- // TODO: Get rid of clones
+ // Clone so we can use these values in the thread
+ // closure. Since both closures are required to be
+ // 'static, we can't use references to these values.
let jenkins_url = jenkins_url.clone();
let jenkins_user_id = jenkins_user_id.clone();
let jenkins_token = jenkins_token.clone();
@@ -150,17 +152,13 @@ fn main() {
match jenkins::find_and_track_build_and_update_status(
commit_ref,
- &jenkins_url,
+ jenkins_url,
&jenkins_user_id,
&jenkins_token,
- &github_token,
+ github_token,
) {
Ok(_) => {},
- Err(e) => {
- error!("{}", e.to_string());
-
- // return internal_server_error()
- },
+ Err(e) => error!("{}", e.to_string()),
};
});