Pipeline: Avoid spamming stderr when not needed

This commit add a new DataError Variant for feeds that return 304.
Its expected behaviror and the current API of Source::into_feed
is kinda limiting the return type to make it easier to handle.

Up till now 304 was returning an Error to early return. Ideally
Source::into_feed will return a Multi variant Result Enum.

example:

enum FeedResult {
    Ok(Success(feed)),
    Ok(NotModified),
    Err(err),
}

Hopefully in a refactor in the near Future™

Till then we will just have to match and ignore
DataError::FeedNotModified.
This commit is contained in:
Jordan Petridis 2018-09-04 14:12:05 +03:00
parent ca6996e53a
commit da361d0cb9
No known key found for this signature in database
GPG Key ID: E8523968931763BE
3 changed files with 13 additions and 3 deletions

View File

@ -65,6 +65,8 @@ pub enum DataError {
HttpStatusGeneral(HttpStatusError), HttpStatusGeneral(HttpStatusError),
#[fail(display = "Source redirects to a new url")] #[fail(display = "Source redirects to a new url")]
FeedRedirect(Source), FeedRedirect(Source),
#[fail(display = "Feed is up to date")]
FeedNotModified(Source),
#[fail( #[fail(
display = "Error occured while Parsing an Episode. Reason: {}", display = "Error occured while Parsing an Episode. Reason: {}",
reason reason

View File

@ -144,7 +144,10 @@ impl Source {
}; };
match code { match code {
StatusCode::NotModified => return Err(self.make_err("304: skipping..", code)), StatusCode::NotModified => {
info!("304: Source, (id: {}), is up to date", self.id());
return Err(DataError::FeedNotModified(self));
}
StatusCode::MovedPermanently | StatusCode::Found | StatusCode::PermanentRedirect => { StatusCode::MovedPermanently | StatusCode::Found | StatusCode::PermanentRedirect => {
warn!("Feed was moved permanently."); warn!("Feed was moved permanently.");
self = self.update_url(&res)?; self = self.update_url(&res)?;

View File

@ -38,8 +38,13 @@ where
}) })
// the stream will stop at the first error so // the stream will stop at the first error so
// we ensure that everything will succeded regardless. // we ensure that everything will succeded regardless.
.map_err(|err| error!("Error: {}", err)) .map_err(|err| {
.then(|_| ok::<(), DataError>(())) match err {
// Avoid spamming the stderr when its not an eactual error
DataError::FeedNotModified(_) => (),
_ => error!("Error: {}", err),
}
}).then(|_| ok::<(), DataError>(()))
.collect() .collect()
} }