From 130669793dfb77b286a26a373378b4d1f2be837c Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Sat, 26 Oct 2024 02:20:32 -0400 Subject: Very basic rocket db state and session lookup (with hardcoded session id) --- src/jobs/startup.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/jobs/startup.rs') 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::(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() { -- cgit 1.4.1