diff --git a/src/tasks.rs b/src/tasks.rs index 88a4d22..47c8ce8 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -11,6 +11,7 @@ static DB_POOL: OnceLock = OnceLock::new(); /// Spawn a task to take care of running periodic background tasks. pub async fn spawn(rocket: rocket::Rocket) -> rocket::fairing::Result { + println!("here"); let Some(db) = database::Main::fetch(&rocket) else { eprintln!("couldn't retrieve db pool to set up background tasks"); return Err(rocket); @@ -23,15 +24,17 @@ pub async fn spawn(rocket: rocket::Rocket) -> rocket::fairing::Re scheduler .every(1.day()) .at("00:00") + .every(1.minute()) .run(|| run_background_task("ensure daily chosen at midnight", ensure_daily_chosen)); scheduler .every(1.minute()) .run(|| run_background_task("end timed-out games", end_timed_out_games)); rocket::tokio::task::spawn(async move { // Check for new tasks once a minute. - // FIXME: these tasks don't appear to be actually running - scheduler.run_pending().await; - rocket::tokio::time::sleep(std::time::Duration::from_secs(60)).await; + loop { + scheduler.run_pending().await; + rocket::tokio::time::sleep(std::time::Duration::from_secs(60)).await; + } }); Ok(rocket) } @@ -70,9 +73,11 @@ async fn db_conn() -> Result> { /// and also ensures that the database is populated with tracks and related data for /// other tasks. async fn ensure_daily_chosen() -> Result<()> { + println!("here...."); track::pick::daily(&mut *db_conn().await?) .await .wrap_err("error picking a daily track as a background task")?; + println!("done!"); Ok(()) }