From 0e580292a6fe4da501347fa7d51be3809759bbd6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 5 Jul 2024 01:44:43 +0000 Subject: [PATCH] encap admin handler init/fini in crate Signed-off-by: Jason Volk --- src/admin/mod.rs | 13 ++++++++++++- src/router/run.rs | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/admin/mod.rs b/src/admin/mod.rs index f2034724..7bb22418 100644 --- a/src/admin/mod.rs +++ b/src/admin/mod.rs @@ -17,7 +17,6 @@ extern crate conduit_core as conduit; extern crate conduit_service as service; pub(crate) use conduit::{mod_ctor, mod_dtor, Result}; -pub use handler::handle; pub(crate) use service::{services, user_is_local}; pub(crate) use crate::{ @@ -28,6 +27,18 @@ pub(crate) use crate::{ mod_ctor! {} mod_dtor! {} +/// Install the admin command handler +#[allow(clippy::let_underscore_must_use)] +pub async fn init() { + _ = services().admin.handle.lock().await.insert(handler::handle); +} + +/// Uninstall the admin command handler +#[allow(clippy::let_underscore_must_use)] +pub async fn fini() { + _ = services().admin.handle.lock().await.take(); +} + #[cfg(test)] mod test { use clap::Parser; diff --git a/src/router/run.rs b/src/router/run.rs index fb59c797..4f7853d8 100644 --- a/src/router/run.rs +++ b/src/router/run.rs @@ -22,7 +22,7 @@ pub(crate) async fn run(server: Arc) -> Result<(), Error> { let app = layers::build(&server)?; // Install the admin room callback here for now - _ = services().admin.handle.lock().await.insert(admin::handle); + admin::init().await; // Setup shutdown/signal handling let handle = ServerHandle::new(); @@ -39,7 +39,7 @@ pub(crate) async fn run(server: Arc) -> Result<(), Error> { _ = sigs.await; // Remove the admin room callback - _ = services().admin.handle.lock().await.take(); + admin::fini().await; debug_info!("Finished"); res