From 25fe4c23ef64b31ab07cef974ae6927fe7ed1caa Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 30 Apr 2024 15:47:40 +0200 Subject: [PATCH] remove unnecessary async --- src/main.rs | 2 +- src/scheduled/mod.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2377915..8c1bf89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ async fn rocket() -> _ { .await .unwrap(); - scheduled::schedule(&db).await; + scheduled::schedule(&db); let rocket = rocket::build().manage(db); diff --git a/src/scheduled/mod.rs b/src/scheduled/mod.rs index 60e9da0..381a546 100644 --- a/src/scheduled/mod.rs +++ b/src/scheduled/mod.rs @@ -6,18 +6,19 @@ use job_scheduler_ng::{Job, JobScheduler}; use rocket::tokio::{self, task}; use sqlx::SqlitePool; -pub async fn schedule(db: &SqlitePool) { +pub fn schedule(db: &SqlitePool) { let db = db.clone(); - waterlevel::update(&db).await.unwrap(); - tokio::task::spawn(async { + waterlevel::update(&db).await.unwrap(); + let mut sched = JobScheduler::new(); // Every hour sched.add(Job::new("0 0 * * * * *".parse().unwrap(), move || { let db_clone = db.clone(); - // Use block_in_place to run async code in the synchronous function + // Use block_in_place to run async code in the synchronous function; TODO: Make it + // 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(); -- 2.45.2