mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-19 14:08:45 -04:00
Merge remote-tracking branch 'origin/main' into use-rust-shortcuts
This commit is contained in:
BIN
Cargo.lock
generated
BIN
Cargo.lock
generated
Binary file not shown.
@@ -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);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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!");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user