From 3dc749821107743454cf05fffa1ea8068e2fa09c Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 7 Apr 2020 08:16:08 -0400 Subject: [PATCH] retry a job if we get an expired creds error --- ofborg/src/commitstatus.rs | 6 ++++++ ofborg/src/message/evaluationjob.rs | 4 ++++ ofborg/src/tasks/evaluate.rs | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/ofborg/src/commitstatus.rs b/ofborg/src/commitstatus.rs index d12b5c3..3ad3d1b 100644 --- a/ofborg/src/commitstatus.rs +++ b/ofborg/src/commitstatus.rs @@ -71,6 +71,7 @@ impl<'a> CommitStatus<'a> { #[derive(Debug)] pub enum CommitStatusError { + ExpiredCreds(hubcaps::Error), MissingSHA(hubcaps::Error), Error(hubcaps::Error), } @@ -79,6 +80,11 @@ impl From for CommitStatusError { fn from(e: hubcaps::Error) -> CommitStatusError { use hyper::status::StatusCode; match e.kind() { + hubcaps::ErrorKind::Fault { code, error } + if code == &StatusCode::Unauthorized && error.message == "Bad credentials" => + { + CommitStatusError::ExpiredCreds(e) + } hubcaps::ErrorKind::Fault { code, error } if code == &StatusCode::UnprocessableEntity && error.message.starts_with("No commit found for SHA:") => diff --git a/ofborg/src/message/evaluationjob.rs b/ofborg/src/message/evaluationjob.rs index e2d9358..0f9818e 100644 --- a/ofborg/src/message/evaluationjob.rs +++ b/ofborg/src/message/evaluationjob.rs @@ -20,6 +20,10 @@ impl EvaluationJob { pub struct Actions {} impl Actions { + pub fn retry_later(&mut self, _job: &EvaluationJob) -> worker::Actions { + vec![worker::Action::NackRequeue] + } + pub fn skip(&mut self, _job: &EvaluationJob) -> worker::Actions { vec![worker::Action::Ack] } diff --git a/ofborg/src/tasks/evaluate.rs b/ofborg/src/tasks/evaluate.rs index 965ad55..40da52a 100644 --- a/ofborg/src/tasks/evaluate.rs +++ b/ofborg/src/tasks/evaluate.rs @@ -226,6 +226,10 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { self.actions().skip(&self.job) } + Err(Err(CommitStatusError::ExpiredCreds(e))) => { + error!("Failed writing commit status: creds expired: {:?}", e); + self.actions().retry_later(&self.job) + } Err(Err(CommitStatusError::MissingSHA(e))) => { error!( "Failed writing commit status: commit sha was force-pushed away: {:?}",