From ce8a095b31d676728aafdd89fd3f50cc8b29ff4a Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 10 Jul 2024 09:44:38 +0200 Subject: [PATCH] more robust data fetching --- src/scheduled/mod.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/scheduled/mod.rs b/src/scheduled/mod.rs index 93d09ec..acae7df 100644 --- a/src/scheduled/mod.rs +++ b/src/scheduled/mod.rs @@ -14,8 +14,12 @@ pub fn schedule(db: &SqlitePool, config: &Config) { let openweathermap_key = config.openweathermap_key.clone(); tokio::task::spawn(async { - waterlevel::update(&db).await.unwrap(); - weather::update(&db, &openweathermap_key).await.unwrap(); + if let Err(e) = waterlevel::update(&db).await { + log::error!("Water level update error: {e}, trying again next time"); + } + if let Err(e) = weather::update(&db, &openweathermap_key).await { + log::error!("Weather update error: {e}, trying again next time"); + } let mut sched = JobScheduler::new(); @@ -26,10 +30,12 @@ pub fn schedule(db: &SqlitePool, config: &Config) { // nicer one's rust (stable) support async closures task::block_in_place(|| { tokio::runtime::Handle::current().block_on(async { - waterlevel::update(&db_clone).await.unwrap(); - weather::update(&db_clone, &openweathermap_key) - .await - .unwrap(); + if let Err(e) = waterlevel::update(&db_clone).await { + log::error!("Water level update error: {e}, trying again next time"); + } + if let Err(e) = weather::update(&db_clone, &openweathermap_key).await { + log::error!("Weather update error: {e}, trying again next time"); + } }); }); })); -- 2.45.2