misc simplifications and cleanup

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-05-25 20:16:28 +00:00
parent 90d9a997a5
commit 1108235c63
2 changed files with 10 additions and 13 deletions

View file

@ -25,21 +25,20 @@ fn main() -> Result<(), Error> {
.build() .build()
.expect("built runtime"); .expect("built runtime");
let handle = runtime.handle(); let server: Arc<Server> = Server::build(args, Some(runtime.handle()))?;
let server: Arc<Server> = Server::build(args, Some(handle))?; runtime.block_on(async_main(&server))?;
runtime.block_on(async { async_main(server.clone()).await })?;
// explicit drop here to trace thread and tls dtors // explicit drop here to trace thread and tls dtors
drop(runtime); drop(runtime);
debug_info!("Exit"); debug_info!("Exit");
Ok(()) Ok(())
} }
/// Operate the server normally in release-mode static builds. This will start, /// Operate the server normally in release-mode static builds. This will start,
/// run and stop the server within the asynchronous runtime. /// run and stop the server within the asynchronous runtime.
#[cfg(not(conduit_mods))] #[cfg(not(conduit_mods))]
async fn async_main(server: Arc<Server>) -> Result<(), Error> { async fn async_main(server: &Arc<Server>) -> Result<(), Error> {
extern crate conduit_router as router; extern crate conduit_router as router;
use tracing::error; use tracing::error;
@ -66,22 +65,22 @@ async fn async_main(server: Arc<Server>) -> Result<(), Error> {
/// and hot-reload portions of the server as-needed before returning for an /// and hot-reload portions of the server as-needed before returning for an
/// actual shutdown. This is not available in release-mode or static builds. /// actual shutdown. This is not available in release-mode or static builds.
#[cfg(conduit_mods)] #[cfg(conduit_mods)]
async fn async_main(server: Arc<Server>) -> Result<(), Error> { async fn async_main(server: &Arc<Server>) -> Result<(), Error> {
let mut starts = true; let mut starts = true;
let mut reloads = true; let mut reloads = true;
while reloads { while reloads {
if let Err(error) = mods::open(&server).await { if let Err(error) = mods::open(server).await {
error!("Loading router: {error}"); error!("Loading router: {error}");
return Err(error); return Err(error);
} }
let result = mods::run(&server, starts).await; let result = mods::run(server, starts).await;
if let Ok(result) = result { if let Ok(result) = result {
(starts, reloads) = result; (starts, reloads) = result;
} }
let force = !reloads || result.is_err(); let force = !reloads || result.is_err();
if let Err(error) = mods::close(&server, force).await { if let Err(error) = mods::close(server, force).await {
error!("Unloading router: {error}"); error!("Unloading router: {error}");
return Err(error); return Err(error);
} }

View file

@ -139,9 +139,7 @@ fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) {
let (flame_layer, flame_guard) = let (flame_layer, flame_guard) =
match tracing_flame::FlameLayer::with_file(&config.tracing_flame_output_path) { match tracing_flame::FlameLayer::with_file(&config.tracing_flame_output_path) {
Ok(ok) => ok, Ok(ok) => ok,
Err(e) => { Err(e) => panic!("failed to initialize tracing-flame: {e}"),
panic!("failed to initialize tracing-flame: {e}");
},
}; };
let flame_layer = flame_layer let flame_layer = flame_layer
.with_empty_samples(false) .with_empty_samples(false)
@ -175,7 +173,7 @@ fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) {
#[cfg_attr(not(feature = "perf_measurements"), allow(clippy::let_unit_value))] #[cfg_attr(not(feature = "perf_measurements"), allow(clippy::let_unit_value))]
let flame_guard = (); let flame_guard = ();
tracing::subscriber::set_global_default(subscriber).unwrap(); tracing::subscriber::set_global_default(subscriber).expect("failed to set global tracing subscriber");
#[cfg(all(feature = "tokio_console", feature = "release_max_log_level", tokio_unstable))] #[cfg(all(feature = "tokio_console", feature = "release_max_log_level", tokio_unstable))]
tracing::error!( tracing::error!(