encap admin handler init/fini in crate

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-05 01:44:43 +00:00
parent 38a24e0170
commit 0e580292a6
2 changed files with 14 additions and 3 deletions

View File

@ -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;

View File

@ -22,7 +22,7 @@ pub(crate) async fn run(server: Arc<Server>) -> 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<Server>) -> Result<(), Error> {
_ = sigs.await;
// Remove the admin room callback
_ = services().admin.handle.lock().await.take();
admin::fini().await;
debug_info!("Finished");
res