properly shutdown the core when using server

This commit is contained in:
Oscar Beaumont committed 2022-09-14 19:02:11 +08:00
1 parent 2fda5b9ca6
commit dd04625a4f
6 files changed
+39 -41

No files matched your search

Generated
+22 -22
View File
@@ -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",
+2 -2
View File
@@ -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);
}
})
+2 -9
View File
@@ -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!");
}
+5 -1
View File
@@ -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<Node>) {
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;
}
+3 -4
View File
@@ -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!");
}
}
+5 -3
View File
@@ -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<NewClientError>),
#[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<PrismaClient, MigrationError> {
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
};