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 <jason@zemos.net>
This commit is contained in:
parent
f4db6292b3
commit
f047675a63
3 changed files with 18 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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<Services>, command: CommandInput) -> HandlerFuture {
|
||||
pub(super) fn dispatch(services: Arc<Services>, command: CommandInput) -> ProcessorFuture {
|
||||
Box::pin(handle_command(services, command))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, name = "admin")]
|
||||
async fn handle_command(services: Arc<Services>, command: CommandInput) -> HandlerResult {
|
||||
async fn handle_command(services: Arc<Services>, command: CommandInput) -> ProcessorResult {
|
||||
AssertUnwindSafe(Box::pin(process_command(services, &command)))
|
||||
.catch_unwind()
|
||||
.await
|
||||
|
@ -68,7 +68,7 @@ async fn process_command(services: Arc<Services>, 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);
|
|
@ -29,7 +29,7 @@ pub struct Service {
|
|||
services: Services,
|
||||
sender: Sender<CommandInput>,
|
||||
receiver: Mutex<Receiver<CommandInput>>,
|
||||
pub handle: RwLock<Option<Handler>>,
|
||||
pub handle: RwLock<Option<Processor>>,
|
||||
pub complete: StdRwLock<Option<Completer>>,
|
||||
#[cfg(feature = "console")]
|
||||
pub console: Arc<console::Console>,
|
||||
|
@ -52,9 +52,9 @@ pub struct CommandInput {
|
|||
}
|
||||
|
||||
pub type Completer = fn(&str) -> String;
|
||||
pub type Handler = fn(Arc<crate::Services>, CommandInput) -> HandlerFuture;
|
||||
pub type HandlerFuture = Pin<Box<dyn Future<Output = HandlerResult> + Send>>;
|
||||
pub type HandlerResult = Result<CommandOutput>;
|
||||
pub type Processor = fn(Arc<crate::Services>, CommandInput) -> ProcessorFuture;
|
||||
pub type ProcessorFuture = Pin<Box<dyn Future<Output = ProcessorResult> + Send>>;
|
||||
pub type ProcessorResult = Result<CommandOutput>;
|
||||
pub type CommandOutput = Option<RoomMessageEventContent>;
|
||||
|
||||
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<OwnedEventId>,
|
||||
) -> Result<Option<RoomMessageEventContent>> {
|
||||
pub async fn command_in_place(&self, command: String, reply_id: Option<OwnedEventId>) -> 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
|
||||
|
|
Loading…
Add table
Reference in a new issue