mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 11:39:48 +00:00
Refactored the shutdown creation
This commit is contained in:
parent
dcc616f5f0
commit
fa4071222e
@ -1,6 +1,4 @@
|
||||
#[cfg(unix)]
|
||||
use std::collections::HashSet;
|
||||
|
||||
use log::info;
|
||||
use once_cell::sync::Lazy;
|
||||
use rocket::config::Shutdown;
|
||||
@ -28,24 +26,8 @@ pub fn start_runtime_api() {
|
||||
let api_port = *API_SERVER_PORT;
|
||||
info!("Try to start the API server on 'http://localhost:{api_port}'...");
|
||||
|
||||
// The shutdown configuration for the runtime API server:
|
||||
let shutdown = Shutdown {
|
||||
// We do not want to use the Ctrl+C signal to stop the server:
|
||||
ctrlc: false,
|
||||
|
||||
// Everything else is set to default for now:
|
||||
..Shutdown::default()
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
// Now, shutdown needs to be mutable:
|
||||
let mut shutdown = shutdown;
|
||||
|
||||
// We do not want to use the termination signal to stop the server.
|
||||
// This option, however, is only available on Unix systems:
|
||||
shutdown.signals = HashSet::new();
|
||||
}
|
||||
// Get the shutdown configuration:
|
||||
let shutdown = create_shutdown(cfg!(windows));
|
||||
|
||||
// Configure the runtime API server:
|
||||
let figment = Figment::from(rocket::Config::release_default())
|
||||
@ -101,3 +83,19 @@ pub fn start_runtime_api() {
|
||||
.launch().await.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
fn create_shutdown(for_windows: bool) -> Shutdown {
|
||||
let mut shutdown = Shutdown {
|
||||
// We do not want to use the Ctrl+C signal to stop the server:
|
||||
ctrlc: false,
|
||||
|
||||
// Everything else is set to default for now:
|
||||
..Shutdown::default()
|
||||
};
|
||||
|
||||
if for_windows {
|
||||
shutdown.signals = HashSet::new();
|
||||
}
|
||||
|
||||
shutdown
|
||||
}
|
Loading…
Reference in New Issue
Block a user