start removing the feed entry channel
This commit is contained in:
parent
2cafaee52f
commit
72229bf073
1 changed files with 36 additions and 32 deletions
68
src/lib.rs
68
src/lib.rs
|
|
@ -29,6 +29,7 @@ pub struct BlogdorTheAggregator {
|
|||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub struct FeedEntry {
|
||||
url: String,
|
||||
feed_id: i64,
|
||||
title: String,
|
||||
published: DateTime<Utc>,
|
||||
received: DateTime<Utc>,
|
||||
|
|
@ -111,49 +112,52 @@ async fn check_feeds(db: &SqlitePool, client: &reqwest::Client) {
|
|||
|
||||
async fn check_feed(
|
||||
db: SqlitePool,
|
||||
id: i64,
|
||||
feed_id: i64,
|
||||
client: reqwest::Client,
|
||||
url: String,
|
||||
tx: tokio::sync::mpsc::UnboundedSender<FeedEntry>,
|
||||
) {
|
||||
if let Ok(rec) = sqlx::query!(
|
||||
) -> Result<Vec<FeedEntry>, String> {
|
||||
let rec = sqlx::query!(
|
||||
"select date_time from runs where succeeded = true and feed = ? order by id desc limit 1",
|
||||
id
|
||||
feed_id
|
||||
)
|
||||
.fetch_optional(&db)
|
||||
.await
|
||||
{
|
||||
let last_fetched = rec.map(|d| d.date_time.and_utc()).unwrap_or(LAST_FETCHED);
|
||||
let now = Utc::now();
|
||||
.map_err(|e| format!("Could not fetch runs for {url} from DB, got {e}"))?;
|
||||
|
||||
let feed = client.get(&url).send().await;
|
||||
if let Ok(feed) = feed
|
||||
&& let Ok(feed) = feed.bytes().await
|
||||
&& let Ok(feed) = parse(feed.reader())
|
||||
{
|
||||
for post in feed.entries {
|
||||
let last_year = now - ONE_YEAR;
|
||||
if post.published.unwrap_or(last_year) > last_fetched {
|
||||
let entry = FeedEntry {
|
||||
url: url.clone(),
|
||||
title: post
|
||||
.title
|
||||
.map(|t| t.content)
|
||||
.unwrap_or("Blogdor Says: NO POST TITLE".to_string()),
|
||||
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),
|
||||
};
|
||||
if let Err(e) = tx.send(entry) {
|
||||
tracing::error!("error sending feed entry: {e}");
|
||||
continue;
|
||||
};
|
||||
// update DB
|
||||
}
|
||||
let last_fetched = rec.map(|d| d.date_time.and_utc()).unwrap_or(LAST_FETCHED);
|
||||
let now = Utc::now();
|
||||
let mut out = Vec::new();
|
||||
let feed = client.get(&url).send().await;
|
||||
if let Ok(feed) = feed
|
||||
&& let Ok(feed) = feed.bytes().await
|
||||
&& let Ok(feed) = parse(feed.reader())
|
||||
{
|
||||
for post in feed.entries {
|
||||
let last_year = now - ONE_YEAR;
|
||||
if post.published.unwrap_or(last_year) > last_fetched {
|
||||
let entry = FeedEntry {
|
||||
url: post
|
||||
.links
|
||||
.first()
|
||||
.cloned()
|
||||
.map(|l| l.href)
|
||||
.unwrap_or("".to_string()),
|
||||
feed_id,
|
||||
title: post
|
||||
.title
|
||||
.map(|t| t.content)
|
||||
.unwrap_or("Blogdor Says: NO POST TITLE".to_string()),
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue