diff options
author | Ashelyn Rose <git@ashen.earth> | 2024-10-26 02:20:32 -0400 |
---|---|---|
committer | Ashelyn Rose <git@ashen.earth> | 2024-10-26 02:20:32 -0400 |
commit | 130669793dfb77b286a26a373378b4d1f2be837c (patch) | |
tree | b2867473b4610e3f79c3098bf661435c25fcee5c /src/jobs | |
parent | 2eee33d2a2042b209dd5f9ef4b7314ea81a33360 (diff) |
Very basic rocket db state and session lookup (with hardcoded session id)
Diffstat (limited to 'src/jobs')
-rw-r--r-- | src/jobs/startup.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/jobs/startup.rs b/src/jobs/startup.rs index 05eaa94..6ca1849 100644 --- a/src/jobs/startup.rs +++ b/src/jobs/startup.rs @@ -1,16 +1,27 @@ use tokio::runtime; -use std::{fs, path::Path}; +use std::{fs, path::Path, thread}; +use tokio::sync::mpsc::channel; use sqlx::{migrate::Migrator, Connection, PgConnection, Row}; -pub fn run_startup_jobs() { - let runtime = runtime::Builder::new_current_thread() - .enable_all() - .build().unwrap(); +type JobResult = Result<(), ()>; - runtime.block_on(async { - migrate_db().await - }) +pub async fn run_startup_jobs() { + let (tx, mut rx) = channel::<JobResult>(1); + + thread::spawn(move || { + let runtime = runtime::Builder::new_current_thread() + .enable_all() + .build().unwrap(); + + runtime.block_on(async { + migrate_db().await; + + tx.send(Ok(())).await.unwrap() + }); + }); + + rx.recv().await; } async fn migrate_db() { |