Allow passing permanent failures up as errors

This commit is contained in:
Olivier 'reivilibre' 2022-06-05 10:09:03 +01:00
parent fb3eae9226
commit e66ac80484
2 changed files with 26 additions and 9 deletions

View File

@ -17,6 +17,8 @@ use reqwest::{Client, Response, Url};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sitemap::reader::SiteMapEntity; use sitemap::reader::SiteMapEntity;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::io::Cursor; use std::io::Cursor;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
@ -125,8 +127,17 @@ pub enum PermanentFailureReason {
DeniedToRobots, DeniedToRobots,
WrongLanguage(String), WrongLanguage(String),
UnknownContentType(String), UnknownContentType(String),
ExceedsSizeLimit,
} }
impl Display for PermanentFailure {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&self, f)
}
}
impl Error for PermanentFailure {}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum RakeIntent { pub enum RakeIntent {
Any, Any,

View File

@ -260,6 +260,10 @@ impl TaskContext {
let rake_outcome = raked.unwrap_or_else(|err| { let rake_outcome = raked.unwrap_or_else(|err| {
warn!("Failed to rake {:?}: {:?}", url, err); warn!("Failed to rake {:?}: {:?}", url, err);
match err.downcast::<PermanentFailure>() {
Ok(permanent) => RakeOutcome::PermanentFailure(permanent),
Err(err) => {
// Treat this as a temporary rejection (backoff). // Treat this as a temporary rejection (backoff).
RakeOutcome::TemporaryFailure(TemporaryFailure { RakeOutcome::TemporaryFailure(TemporaryFailure {
reason: TemporaryFailureReason::UnknownClientError(format!( reason: TemporaryFailureReason::UnknownClientError(format!(
@ -269,6 +273,8 @@ impl TaskContext {
// Back off for a day: this ought to be enough time for the operator to fix the problem... maybe? // Back off for a day: this ought to be enough time for the operator to fix the problem... maybe?
backoff_sec: 86400, backoff_sec: 86400,
}) })
}
}
}); });
match self.process_outcome(&url, rake_outcome).await? { match self.process_outcome(&url, rake_outcome).await? {