retry a job if we get an expired creds error

This commit is contained in:
Graham Christensen 2020-04-07 08:16:08 -04:00
parent e65a24aa89
commit 3dc7498211
No known key found for this signature in database
GPG key ID: FE918C3A98C1030F
3 changed files with 14 additions and 0 deletions

View file

@ -71,6 +71,7 @@ impl<'a> CommitStatus<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum CommitStatusError { pub enum CommitStatusError {
ExpiredCreds(hubcaps::Error),
MissingSHA(hubcaps::Error), MissingSHA(hubcaps::Error),
Error(hubcaps::Error), Error(hubcaps::Error),
} }
@ -79,6 +80,11 @@ impl From<hubcaps::Error> for CommitStatusError {
fn from(e: hubcaps::Error) -> CommitStatusError { fn from(e: hubcaps::Error) -> CommitStatusError {
use hyper::status::StatusCode; use hyper::status::StatusCode;
match e.kind() { match e.kind() {
hubcaps::ErrorKind::Fault { code, error }
if code == &StatusCode::Unauthorized && error.message == "Bad credentials" =>
{
CommitStatusError::ExpiredCreds(e)
}
hubcaps::ErrorKind::Fault { code, error } hubcaps::ErrorKind::Fault { code, error }
if code == &StatusCode::UnprocessableEntity if code == &StatusCode::UnprocessableEntity
&& error.message.starts_with("No commit found for SHA:") => && error.message.starts_with("No commit found for SHA:") =>

View file

@ -20,6 +20,10 @@ impl EvaluationJob {
pub struct Actions {} pub struct Actions {}
impl 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 { pub fn skip(&mut self, _job: &EvaluationJob) -> worker::Actions {
vec![worker::Action::Ack] vec![worker::Action::Ack]
} }

View file

@ -226,6 +226,10 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> {
self.actions().skip(&self.job) 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))) => { Err(Err(CommitStatusError::MissingSHA(e))) => {
error!( error!(
"Failed writing commit status: commit sha was force-pushed away: {:?}", "Failed writing commit status: commit sha was force-pushed away: {:?}",