rename runs to successful_runs

This commit is contained in:
joe 2025-12-13 15:25:46 -08:00
parent 2de9c744d7
commit 4434a31c09
2 changed files with 9 additions and 9 deletions

View file

@ -1,7 +1,6 @@
CREATE TABLE IF NOT EXISTS runs ( CREATE TABLE IF NOT EXISTS successful_runs (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
date_time DATETIME NOT NULL DEFAULT current_timestamp, date_time DATETIME NOT NULL DEFAULT current_timestamp,
succeeded BOOLEAN NOT NULL DEFAULT FALSE,
feed INTEGER NOT NULL, feed INTEGER NOT NULL,
FOREIGN KEY (feed) REFERENCES feeds(id) FOREIGN KEY (feed) REFERENCES feeds(id)
); );

View file

@ -167,12 +167,10 @@ async fn check_feeds(db: &SqlitePool, client: &reqwest::Client) {
tokio::time::sleep(Duration::from_millis(200)).await; tokio::time::sleep(Duration::from_millis(200)).await;
} }
if success if success
&& let Err(e) = sqlx::query!( && let Err(e) =
"insert into runs (feed, succeeded) values (?, true)", sqlx::query!("insert into successful_runs (feed) values (?)", feed_id)
feed_id .execute(db)
) .await
.execute(db)
.await
{ {
tracing::error!("could not insert run for {feed_id}, got {e}"); tracing::error!("could not insert run for {feed_id}, got {e}");
} }
@ -188,13 +186,14 @@ async fn check_feed(
url: String, url: String,
) -> Result<Option<Vec<FeedEntry>>, String> { ) -> Result<Option<Vec<FeedEntry>>, String> {
let 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 successful_runs where feed = ? order by id desc limit 1",
feed_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}"))?; .map_err(|e| format!("Could not fetch runs for {url} from DB, got {e}"))?;
tracing::debug!("checking {url}");
let last_fetched = rec.map(|d| d.date_time.and_utc()).unwrap_or(LAST_FETCHED); let last_fetched = rec.map(|d| d.date_time.and_utc()).unwrap_or(LAST_FETCHED);
let now = Utc::now(); let now = Utc::now();
let mut out = Vec::new(); let mut out = Vec::new();
@ -241,8 +240,10 @@ async fn check_feed(
} }
if out.is_empty() { if out.is_empty() {
tracing::debug!("no new items from {url}");
Ok(None) Ok(None)
} else { } else {
tracing::debug!("found {} new items from {url}", out.len());
Ok(Some(out)) Ok(Some(out))
} }
} }