Refactored the shutdown creation, again

This commit is contained in:
Thorsten Sommer 2025-02-27 08:25:10 +01:00
parent fa4071222e
commit a1441b7fe1
No known key found for this signature in database
GPG Key ID: B0B7E2FC074BF1F5

View File

@ -1,4 +1,3 @@
use std::collections::HashSet;
use log::info; use log::info;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use rocket::config::Shutdown; use rocket::config::Shutdown;
@ -27,7 +26,7 @@ pub fn start_runtime_api() {
info!("Try to start the API server on 'http://localhost:{api_port}'..."); info!("Try to start the API server on 'http://localhost:{api_port}'...");
// Get the shutdown configuration: // Get the shutdown configuration:
let shutdown = create_shutdown(cfg!(windows)); let shutdown = create_shutdown();
// Configure the runtime API server: // Configure the runtime API server:
let figment = Figment::from(rocket::Config::release_default()) let figment = Figment::from(rocket::Config::release_default())
@ -84,7 +83,13 @@ pub fn start_runtime_api() {
}); });
} }
fn create_shutdown(for_windows: bool) -> Shutdown { fn create_shutdown() -> Shutdown {
//
// Create a shutdown configuration, depending on the operating system:
//
#[cfg(unix)]
{
use std::collections::HashSet;
let mut shutdown = Shutdown { let mut shutdown = Shutdown {
// We do not want to use the Ctrl+C signal to stop the server: // We do not want to use the Ctrl+C signal to stop the server:
ctrlc: false, ctrlc: false,
@ -93,9 +98,18 @@ fn create_shutdown(for_windows: bool) -> Shutdown {
..Shutdown::default() ..Shutdown::default()
}; };
if for_windows {
shutdown.signals = HashSet::new(); shutdown.signals = HashSet::new();
shutdown
} }
shutdown #[cfg(windows)]
{
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()
}
}
} }