diff --git a/Cargo.lock b/Cargo.lock index ebce41f96..9c0872bb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -986,7 +986,7 @@ dependencies = [ [[package]] name = "datamodel" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "bigdecimal 0.2.2", "chrono", @@ -1023,7 +1023,7 @@ dependencies = [ [[package]] name = "datamodel-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "diagnostics 0.1.0 (git+https://github.com/Brendonovich/prisma-engines.git)", "enumflags2", @@ -1099,7 +1099,7 @@ dependencies = [ [[package]] name = "diagnostics" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "colored", "pest", @@ -1191,7 +1191,7 @@ dependencies = [ [[package]] name = "dml" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "chrono", "enumflags2", @@ -2547,7 +2547,7 @@ dependencies = [ [[package]] name = "json-rpc-api-build" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "backtrace", "heck 0.3.3", @@ -3016,7 +3016,7 @@ dependencies = [ [[package]] name = "migration-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "chrono", "datamodel 0.1.0 (git+https://github.com/Brendonovich/prisma-engines.git)", @@ -3030,7 +3030,7 @@ dependencies = [ [[package]] name = "migration-core" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "async-trait", "chrono", @@ -3162,7 +3162,7 @@ dependencies = [ [[package]] name = "mongodb-client" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "mongodb", "once_cell", @@ -3185,7 +3185,7 @@ dependencies = [ [[package]] name = "mongodb-datamodel-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "datamodel-connector 0.1.0 (git+https://github.com/Brendonovich/prisma-engines.git)", "enumflags2", @@ -3197,7 +3197,7 @@ dependencies = [ [[package]] name = "mongodb-migration-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "datamodel 0.1.0 (git+https://github.com/Brendonovich/prisma-engines.git)", "enumflags2", @@ -3248,7 +3248,7 @@ dependencies = [ [[package]] name = "mongodb-schema-describer" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "futures", "mongodb", @@ -3372,7 +3372,7 @@ dependencies = [ [[package]] name = "native-types" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "serde", "serde_json", @@ -3884,7 +3884,7 @@ dependencies = [ [[package]] name = "parser-database" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "diagnostics 0.1.0 (git+https://github.com/Brendonovich/prisma-engines.git)", "either", @@ -4333,7 +4333,7 @@ dependencies = [ [[package]] name = "prisma-value" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "base64 0.12.3", "bigdecimal 0.2.2", @@ -4407,7 +4407,7 @@ dependencies = [ [[package]] name = "psl" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "datamodel 0.1.0 (git+https://github.com/Brendonovich/prisma-engines.git)", ] @@ -5109,7 +5109,7 @@ dependencies = [ [[package]] name = "schema-ast" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "diagnostics 0.1.0 (git+https://github.com/Brendonovich/prisma-engines.git)", "pest", @@ -5669,7 +5669,7 @@ dependencies = [ [[package]] name = "sql-datamodel-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "connection-string", "datamodel-connector 0.1.0 (git+https://github.com/Brendonovich/prisma-engines.git)", @@ -5685,12 +5685,12 @@ dependencies = [ [[package]] name = "sql-ddl" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" [[package]] name = "sql-migration-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "chrono", "connection-string", @@ -5749,7 +5749,7 @@ dependencies = [ [[package]] name = "sql-schema-describer" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "async-trait", "bigdecimal 0.2.2", @@ -6855,7 +6855,7 @@ dependencies = [ [[package]] name = "user-facing-error-macros" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "proc-macro2", "quote", @@ -6879,7 +6879,7 @@ dependencies = [ [[package]] name = "user-facing-errors" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines.git#dcea2c532cb777afb290a613f769140647a16804" +source = "git+https://github.com/Brendonovich/prisma-engines.git#1a9235ce5c50bb629cb63235ca8b5ca82198cada" dependencies = [ "backtrace", "indoc", diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 9fb97486e..bc33381af 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use sdcore::Node; -use tauri::{api::path, Manager, RunEvent}; +use tauri::{api::path, async_runtime::block_on, Manager, RunEvent}; use tracing::{debug, error}; #[cfg(target_os = "macos")] mod macos; @@ -79,7 +79,7 @@ async fn main() { } }); - node.shutdown(); + block_on(node.shutdown()); app_handler.exit(0); } }) diff --git a/apps/server/src/main.rs b/apps/server/src/main.rs index 3711f815b..95e1ccf0c 100644 --- a/apps/server/src/main.rs +++ b/apps/server/src/main.rs @@ -29,14 +29,7 @@ async fn main() { .unwrap_or(8080); let (node, router) = Node::new(data_dir).await; - - ctrlc::set_handler({ - let node = node.clone(); - move || { - node.shutdown(); - } - }) - .expect("Error setting Ctrl-C handler"); + let signal = utils::axum_shutdown_signal(node.clone()); let app = axum::Router::new() .route("/", get(|| async { "Spacedrive Server!" })) @@ -55,7 +48,7 @@ async fn main() { info!("Listening on http://localhost:{}", port); axum::Server::bind(&addr) .serve(app.into_make_service()) - .with_graceful_shutdown(utils::axum_shutdown_signal()) + .with_graceful_shutdown(signal) .await .expect("Error with HTTP server!"); } diff --git a/apps/server/src/utils.rs b/apps/server/src/utils.rs index f6437d365..a6bdc360a 100644 --- a/apps/server/src/utils.rs +++ b/apps/server/src/utils.rs @@ -1,7 +1,10 @@ +use std::sync::Arc; + +use sdcore::Node; use tokio::signal; /// shutdown_signal will inform axum to gracefully shutdown when the process is asked to shutdown. -pub async fn axum_shutdown_signal() { +pub async fn axum_shutdown_signal(node: Arc) { let ctrl_c = async { signal::ctrl_c() .await @@ -25,4 +28,5 @@ pub async fn axum_shutdown_signal() { } println!("signal received, starting graceful shutdown"); + node.shutdown().await; } diff --git a/core/src/lib.rs b/core/src/lib.rs index 776a5e5f5..d7086cd75 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,5 +1,4 @@ use api::{CoreEvent, Ctx, Router}; -use futures::executor::block_on; use job::JobManager; use library::LibraryManager; use node::NodeConfigManager; @@ -116,9 +115,9 @@ impl Node { } } - pub fn shutdown(&self) { + pub async fn shutdown(&self) { info!("Spacedrive shutting down..."); - block_on(self.jobs.pause()); - info!("Shutdown complete."); + self.jobs.pause().await; + info!("Spacedrive Core shutdown successful!"); } } diff --git a/core/src/util/db.rs b/core/src/util/db.rs index 66163895d..9e651e38d 100644 --- a/core/src/util/db.rs +++ b/core/src/util/db.rs @@ -20,7 +20,7 @@ static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/prisma/migrations #[derive(Error, Debug)] pub enum MigrationError { #[error("An error occurred while initialising a new database connection: {0}")] - NewClient(#[from] NewClientError), + NewClient(#[from] Box), #[error("The temporary file path for the database migrations is invalid.")] InvalidDirectory, #[error("An error occurred creating the temporary directory for the migrations: {0}")] @@ -40,7 +40,9 @@ pub async fn load_and_migrate( base_path: &Path, db_url: &str, ) -> Result { - let client = prisma::new_client_with_url(db_url).await?; + let client = prisma::new_client_with_url(db_url) + .await + .map_err(Box::new)?; let temp_migrations_dir = base_path.join("./migrations_temp"); let migrations_directory_path = temp_migrations_dir .to_str() @@ -60,7 +62,7 @@ pub async fn load_and_migrate( .extract(&temp_migrations_dir) .map_err(MigrationError::ExtractMigrations)?; - let mut connector = match &ConnectionInfo::from_url(&db_url)? { + let mut connector = match &ConnectionInfo::from_url(db_url)? { ConnectionInfo::Sqlite { .. } => SqlMigrationConnector::new_sqlite(), ConnectionInfo::InMemorySqlite { .. } => unreachable!(), // This is how it is in the Prisma Rust tests };