Don't fail jobs for fine scenarios

- dont fail contact for breaker
- dont fail instance for not found
This commit is contained in:
asonix 2022-11-15 20:53:55 -06:00
parent 6be72a836b
commit 0768cb6ac6
5 changed files with 34 additions and 16 deletions

View file

@ -18,6 +18,14 @@ impl Error {
pub(crate) fn is_breaker(&self) -> bool { pub(crate) fn is_breaker(&self) -> bool {
matches!(self.kind, ErrorKind::Breaker) matches!(self.kind, ErrorKind::Breaker)
} }
pub(crate) fn is_not_found(&self) -> bool {
matches!(self.kind, ErrorKind::Status(_, StatusCode::NOT_FOUND))
}
pub(crate) fn is_bad_request(&self) -> bool {
matches!(self.kind, ErrorKind::Status(_, StatusCode::BAD_REQUEST))
}
} }
impl std::fmt::Debug for Error { impl std::fmt::Debug for Error {

View file

@ -40,10 +40,18 @@ impl QueryContact {
return Ok(()); return Ok(());
} }
let contact = state let contact = match state
.requests .requests
.fetch::<AcceptedActors>(self.contact_id.as_str()) .fetch::<AcceptedActors>(self.contact_id.as_str())
.await?; .await
{
Ok(contact) => contact,
Err(e) if e.is_breaker() => {
tracing::debug!("Not retrying due to failed breaker");
return Ok(());
}
Err(e) => return Err(e),
};
let (username, display_name, url, avatar) = let (username, display_name, url, avatar) =
to_contact(contact).ok_or(ErrorKind::Extract("contact"))?; to_contact(contact).ok_or(ErrorKind::Extract("contact"))?;

View file

@ -40,6 +40,10 @@ impl Deliver {
tracing::debug!("Not trying due to failed breaker"); tracing::debug!("Not trying due to failed breaker");
return Ok(()); return Ok(());
} }
if e.is_bad_request() {
tracing::debug!("Server didn't understand the activity");
return Ok(());
}
return Err(e); return Err(e);
} }
Ok(()) Ok(())

View file

@ -57,6 +57,10 @@ impl QueryInstance {
tracing::debug!("Not retrying due to failed breaker"); tracing::debug!("Not retrying due to failed breaker");
return Ok(()); return Ok(());
} }
Err(e) if e.is_not_found() => {
tracing::debug!("Server doesn't implement instance endpoint");
return Ok(());
}
Err(e) => return Err(e), Err(e) => return Err(e),
}; };

View file

@ -1,9 +1,6 @@
use crate::error::{Error, ErrorKind}; use crate::error::{Error, ErrorKind};
use activitystreams::iri_string::types::IriString; use activitystreams::iri_string::types::IriString;
use actix_web::{ use actix_web::{http::header::Date, web::Bytes};
http::{header::Date, StatusCode},
web::Bytes,
};
use awc::Client; use awc::Client;
use dashmap::DashMap; use dashmap::DashMap;
use http_signature_normalization_actix::prelude::*; use http_signature_normalization_actix::prelude::*;
@ -394,19 +391,16 @@ impl Requests {
self.reset_err(); self.reset_err();
if !res.status().is_success() { if !res.status().is_success() {
// Bad Request means the server didn't understand our activity - that's fine if let Ok(bytes) = res.body().await {
if res.status() != StatusCode::BAD_REQUEST { if let Ok(s) = String::from_utf8(bytes.as_ref().to_vec()) {
if let Ok(bytes) = res.body().await { if !s.is_empty() {
if let Ok(s) = String::from_utf8(bytes.as_ref().to_vec()) { tracing::warn!("Response from {}, {}", inbox.as_str(), s);
if !s.is_empty() {
tracing::warn!("Response from {}, {}", inbox.as_str(), s);
}
} }
} }
self.breakers.fail(&inbox);
return Err(ErrorKind::Status(inbox.to_string(), res.status()).into());
} }
self.breakers.fail(&inbox);
return Err(ErrorKind::Status(inbox.to_string(), res.status()).into());
} }
self.breakers.succeed(&inbox); self.breakers.succeed(&inbox);