From f047675a63b2f0d15ee538a934b7fdc907e71d91 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 28 Aug 2024 01:33:58 +0000 Subject: [PATCH] rename admin/handler to admin/processor Handler is overused. Handler ought to mean the end-function handling the command. The command processor is the central dispatcher to the handler. Signed-off-by: Jason Volk --- src/admin/mod.rs | 12 ++++++++---- src/admin/{handler.rs => processor.rs} | 8 ++++---- src/service/admin/mod.rs | 14 ++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) rename src/admin/{handler.rs => processor.rs} (96%) diff --git a/src/admin/mod.rs b/src/admin/mod.rs index fb1c02be..83db18fa 100644 --- a/src/admin/mod.rs +++ b/src/admin/mod.rs @@ -4,7 +4,7 @@ pub(crate) mod admin; pub(crate) mod command; -pub(crate) mod handler; +pub(crate) mod processor; mod tests; pub(crate) mod utils; @@ -36,14 +36,18 @@ conduit::mod_ctor! {} conduit::mod_dtor! {} conduit::rustc_flags_capture! {} -/// Install the admin command handler +/// Install the admin command processor pub async fn init(admin_service: &service::admin::Service) { _ = admin_service .complete .write() .expect("locked for writing") - .insert(handler::complete); - _ = admin_service.handle.write().await.insert(handler::handle); + .insert(processor::complete); + _ = admin_service + .handle + .write() + .await + .insert(processor::dispatch); } /// Uninstall the admin command handler diff --git a/src/admin/handler.rs b/src/admin/processor.rs similarity index 96% rename from src/admin/handler.rs rename to src/admin/processor.rs index 631d17e1..2e4330c8 100644 --- a/src/admin/handler.rs +++ b/src/admin/processor.rs @@ -26,7 +26,7 @@ use ruma::{ OwnedEventId, }; use service::{ - admin::{CommandInput, CommandOutput, HandlerFuture, HandlerResult}, + admin::{CommandInput, CommandOutput, ProcessorFuture, ProcessorResult}, Services, }; use tracing::Level; @@ -38,12 +38,12 @@ use crate::{admin, admin::AdminCommand, Command}; pub(super) fn complete(line: &str) -> String { complete_command(AdminCommand::command(), line) } #[must_use] -pub(super) fn handle(services: Arc, command: CommandInput) -> HandlerFuture { +pub(super) fn dispatch(services: Arc, command: CommandInput) -> ProcessorFuture { Box::pin(handle_command(services, command)) } #[tracing::instrument(skip_all, name = "admin")] -async fn handle_command(services: Arc, command: CommandInput) -> HandlerResult { +async fn handle_command(services: Arc, command: CommandInput) -> ProcessorResult { AssertUnwindSafe(Box::pin(process_command(services, &command))) .catch_unwind() .await @@ -68,7 +68,7 @@ async fn process_command(services: Arc, input: &CommandInput) -> Comma .and_then(|content| reply(content, input.reply_id.clone())) } -fn handle_panic(error: &Error, command: CommandInput) -> HandlerResult { +fn handle_panic(error: &Error, command: CommandInput) -> ProcessorResult { let link = "Please submit a [bug report](https://github.com/girlbossceo/conduwuit/issues/new). 🥺"; let msg = format!("Panic occurred while processing command:\n```\n{error:#?}\n```\n{link}"); let content = RoomMessageEventContent::notice_markdown(msg); diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 21ded34d..9e27cdf2 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -29,7 +29,7 @@ pub struct Service { services: Services, sender: Sender, receiver: Mutex>, - pub handle: RwLock>, + pub handle: RwLock>, pub complete: StdRwLock>, #[cfg(feature = "console")] pub console: Arc, @@ -52,9 +52,9 @@ pub struct CommandInput { } pub type Completer = fn(&str) -> String; -pub type Handler = fn(Arc, CommandInput) -> HandlerFuture; -pub type HandlerFuture = Pin + Send>>; -pub type HandlerResult = Result; +pub type Processor = fn(Arc, CommandInput) -> ProcessorFuture; +pub type ProcessorFuture = Pin + Send>>; +pub type ProcessorResult = Result; pub type CommandOutput = Option; const COMMAND_QUEUE_LIMIT: usize = 512; @@ -141,9 +141,7 @@ impl Service { .await; } - pub async fn command_in_place( - &self, command: String, reply_id: Option, - ) -> Result> { + pub async fn command_in_place(&self, command: String, reply_id: Option) -> ProcessorResult { self.process_command(CommandInput { command, reply_id, @@ -176,7 +174,7 @@ impl Service { } } - async fn process_command(&self, command: CommandInput) -> HandlerResult { + async fn process_command(&self, command: CommandInput) -> ProcessorResult { let Some(services) = self .services .services