main: Improve feed parse error handling

This commit is contained in:
mirsal 2024-11-25 04:06:53 +00:00
parent b93f921bcb
commit d0ac11ea89
Signed by: mirsal
GPG Key ID: F78F9FE84AE5B610

View File

@ -39,7 +39,7 @@ use crate::{
}; };
use std::{ sync::Arc, cmp::max }; use std::{ sync::Arc, cmp::max };
use tracing::{ info, debug }; use tracing::{ info, debug, error };
use chrono::DateTime; use chrono::DateTime;
#[tokio::main] #[tokio::main]
@ -63,8 +63,24 @@ async fn main() -> anyhow::Result<()> {
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
let feed = fetch_and_parse_feed(&feed_config.url).await let feed: Option<_> = match fetch_and_parse_feed(&feed_config.url).await {
.expect("Failed to parse feed"); Ok(f) => Some(f),
Err(e) => {
error!("Failed to parse feed {}: {:?}",
feed_config.url,
e
);
None
}
};
let feed = if feed.is_none() {
info!("Sleeping for {} seconds before refreshing this feed", feed_config.delay);
sleep(Duration::from_secs(feed_config.delay)).await;
continue;
} else {
feed.unwrap()
};
let rooms = feed_config.rooms.clone(); let rooms = feed_config.rooms.clone();