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 {
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 {

View file

@ -40,10 +40,18 @@ impl QueryContact {
return Ok(());
}
let contact = state
let contact = match state
.requests
.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) =
to_contact(contact).ok_or(ErrorKind::Extract("contact"))?;

View file

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

View file

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

View file

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