start removing the feed entry channel

This commit is contained in:
Joe 2025-12-12 22:50:31 -08:00
parent 2cafaee52f
commit 72229bf073

View file

@ -29,6 +29,7 @@ pub struct BlogdorTheAggregator {
#[derive(Debug, Default, Clone, PartialEq, Eq)] #[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct FeedEntry { pub struct FeedEntry {
url: String, url: String,
feed_id: i64,
title: String, title: String,
published: DateTime<Utc>, published: DateTime<Utc>,
received: DateTime<Utc>, received: DateTime<Utc>,
@ -111,49 +112,52 @@ async fn check_feeds(db: &SqlitePool, client: &reqwest::Client) {
async fn check_feed( async fn check_feed(
db: SqlitePool, db: SqlitePool,
id: i64, feed_id: i64,
client: reqwest::Client, client: reqwest::Client,
url: String, url: String,
tx: tokio::sync::mpsc::UnboundedSender<FeedEntry>, tx: tokio::sync::mpsc::UnboundedSender<FeedEntry>,
) { ) -> Result<Vec<FeedEntry>, String> {
if let Ok(rec) = sqlx::query!( let rec = sqlx::query!(
"select date_time from runs where succeeded = true and feed = ? order by id desc limit 1", "select date_time from runs where succeeded = true and feed = ? order by id desc limit 1",
id feed_id
) )
.fetch_optional(&db) .fetch_optional(&db)
.await .await
{ .map_err(|e| format!("Could not fetch runs for {url} from DB, got {e}"))?;
let last_fetched = rec.map(|d| d.date_time.and_utc()).unwrap_or(LAST_FETCHED);
let now = Utc::now();
let feed = client.get(&url).send().await; let last_fetched = rec.map(|d| d.date_time.and_utc()).unwrap_or(LAST_FETCHED);
if let Ok(feed) = feed let now = Utc::now();
&& let Ok(feed) = feed.bytes().await let mut out = Vec::new();
&& let Ok(feed) = parse(feed.reader()) let feed = client.get(&url).send().await;
{ if let Ok(feed) = feed
for post in feed.entries { && let Ok(feed) = feed.bytes().await
let last_year = now - ONE_YEAR; && let Ok(feed) = parse(feed.reader())
if post.published.unwrap_or(last_year) > last_fetched { {
let entry = FeedEntry { for post in feed.entries {
url: url.clone(), let last_year = now - ONE_YEAR;
title: post if post.published.unwrap_or(last_year) > last_fetched {
.title let entry = FeedEntry {
.map(|t| t.content) url: post
.unwrap_or("Blogdor Says: NO POST TITLE".to_string()), .links
published: post.published.unwrap_or(now), .first()
received: now, .cloned()
feed_description: feed.description.to_owned().map(|d| d.content), .map(|l| l.href)
body: post.content.and_then(|c| c.body), .unwrap_or("".to_string()),
}; feed_id,
if let Err(e) = tx.send(entry) { title: post
tracing::error!("error sending feed entry: {e}"); .title
continue; .map(|t| t.content)
}; .unwrap_or("Blogdor Says: NO POST TITLE".to_string()),
// update DB published: post.published.unwrap_or(now),
} received: now,
feed_description: feed.description.to_owned().map(|d| d.content),
body: post.content.and_then(|c| c.body),
};
out.push(entry);
} }
} }
} }
todo!()
} }
async fn get_db_pool() -> SqlitePool { async fn get_db_pool() -> SqlitePool {