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 once_cell::sync::Lazy;
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}'...");
// Get the shutdown configuration:
let shutdown = create_shutdown(cfg!(windows));
let shutdown = create_shutdown();
// Configure the runtime API server:
let figment = Figment::from(rocket::Config::release_default())
@ -84,18 +83,33 @@ pub fn start_runtime_api() {
});
}
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,
fn create_shutdown() -> Shutdown {
//
// Create a shutdown configuration, depending on the operating system:
//
#[cfg(unix)]
{
use std::collections::HashSet;
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()
};
// Everything else is set to default for now:
..Shutdown::default()
};
if for_windows {
shutdown.signals = HashSet::new();
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()
}
}
shutdown
}