aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2022-02-14 12:45:55 +0100
committerJakob Stendahl <jakob.stendahl@outlook.com>2022-02-14 12:45:55 +0100
commit2096790f3904371c9ff6090f1ff846593c7df9c4 (patch)
tree96bf58bc2324675b0b9a7cdf9527bfbe7262ccbc /src/main.rs
parentf4a5b478ad103c1fd53d229fc18f2c17a95c8bf1 (diff)
downloadRSS-watcher-0.2.0.tar.gz
RSS-watcher-0.2.0.zip
:children_crossing: Catch and deal with database connection error(s)v0.2.0
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 705fe20..02b386f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -117,6 +117,7 @@ async fn fetch_feed(feed_conf: &FeedConf, last_fetch_time: DateTime<Utc>) -> Res
Ok(None)
} else {
let feed = parser::parse(&resp.bytes().await?[..])?;
+ debug!("{:#?}", feed);
Ok(Some(feed))
}
}
@@ -177,9 +178,26 @@ async fn get_feed(feed_conf: &FeedConf) -> bool {
* This gets all feeds from the database and fetches them once.
*/
async fn main_loop() {
- let mut conn = database::new_conn();
- info!("== Checking for new feed entries now")
- for feed in database::get_feeds(&mut conn) {
+ info!("========== Checking for new feed entries now");
+
+ let res_conn = database::new_conn();
+ if let None = res_conn {
+ error!("Could not open database connection, waiting until next iteration before trying again!");
+ return;
+ };
+ let mut conn = res_conn.unwrap();
+
+ let res_feeds = database::get_feeds(&mut conn);
+
+ if let None = res_feeds {
+ error!("Could not get feeds, waiting until next iteration before trying again!");
+ return;
+ }
+
+ let feeds = res_feeds.unwrap();
+ info!(" Got {} feeds to check", feeds.len());
+
+ for feed in feeds {
let time_now = Utc::now();
let res = get_feed(&feed).await;
if res {