Allow passing permanent failures up as errors
This commit is contained in:
parent
fb3eae9226
commit
e66ac80484
|
@ -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,
|
||||||
|
|
|
@ -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? {
|
||||||
|
|
Loading…
Reference in New Issue