summary refs log tree commit diff
path: root/src/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'src/jobs')
-rw-r--r--src/jobs/startup.rs27
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() {