show waterlevel for the next days
This commit is contained in:
33
src/scheduled/mod.rs
Normal file
33
src/scheduled/mod.rs
Normal file
@ -0,0 +1,33 @@
|
||||
mod waterlevel;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use job_scheduler_ng::{Job, JobScheduler};
|
||||
use rocket::tokio::{self, task};
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
pub async fn schedule(db: &SqlitePool) {
|
||||
let db = db.clone();
|
||||
|
||||
waterlevel::update(&db).await.unwrap();
|
||||
|
||||
tokio::task::spawn(async {
|
||||
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
|
||||
task::block_in_place(|| {
|
||||
tokio::runtime::Handle::current().block_on(async {
|
||||
waterlevel::update(&db_clone).await.unwrap();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
loop {
|
||||
sched.tick();
|
||||
std::thread::sleep(Duration::from_secs(60));
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user