Compare commits

...

2 Commits

Author SHA1 Message Date
6d4bc81720 Merge pull request 'remove unnecessary async' (#469) from show-waterlevel into staging
Some checks failed
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions
CI/CD Pipeline / test (push) Has been cancelled
Reviewed-on: #469
2024-04-30 15:48:45 +02:00
25fe4c23ef remove unnecessary async
Some checks failed
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled
CI/CD Pipeline / test (push) Has been cancelled
2024-04-30 15:47:40 +02:00
2 changed files with 6 additions and 5 deletions

View File

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

View File

@ -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();