Compare commits

..

No commits in common. "6d4bc81720893cb933583083a6e09e8f45bff9c1" and "2fdfddbd2e46da9387eff2a9e69b55958d33a9aa" have entirely different histories.

2 changed files with 5 additions and 6 deletions

View File

@ -27,7 +27,7 @@ async fn rocket() -> _ {
.await .await
.unwrap(); .unwrap();
scheduled::schedule(&db); scheduled::schedule(&db).await;
let rocket = rocket::build().manage(db); let rocket = rocket::build().manage(db);

View File

@ -6,19 +6,18 @@ use job_scheduler_ng::{Job, JobScheduler};
use rocket::tokio::{self, task}; use rocket::tokio::{self, task};
use sqlx::SqlitePool; use sqlx::SqlitePool;
pub fn schedule(db: &SqlitePool) { pub async fn schedule(db: &SqlitePool) {
let db = db.clone(); let db = db.clone();
tokio::task::spawn(async {
waterlevel::update(&db).await.unwrap(); waterlevel::update(&db).await.unwrap();
tokio::task::spawn(async {
let mut sched = JobScheduler::new(); let mut sched = JobScheduler::new();
// Every hour // Every hour
sched.add(Job::new("0 0 * * * * *".parse().unwrap(), move || { sched.add(Job::new("0 0 * * * * *".parse().unwrap(), move || {
let db_clone = db.clone(); let db_clone = db.clone();
// Use block_in_place to run async code in the synchronous function; TODO: Make it // Use block_in_place to run async code in the synchronous function
// nicer one's rust (stable) support async closures
task::block_in_place(|| { task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async { tokio::runtime::Handle::current().block_on(async {
waterlevel::update(&db_clone).await.unwrap(); waterlevel::update(&db_clone).await.unwrap();