add timer around admin command processing
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
b28d216e00
commit
3301cde8e7
1 changed files with 14 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use conduit::trace;
|
use conduit::trace;
|
||||||
use ruma::events::{
|
use ruma::events::{
|
||||||
|
@ -84,11 +86,10 @@ async fn handle_command(command: Command) -> CommandResult {
|
||||||
// Parse and process a message from the admin room
|
// Parse and process a message from the admin room
|
||||||
async fn process_admin_message(msg: String) -> CommandOutput {
|
async fn process_admin_message(msg: String) -> CommandOutput {
|
||||||
let mut lines = msg.lines().filter(|l| !l.trim().is_empty());
|
let mut lines = msg.lines().filter(|l| !l.trim().is_empty());
|
||||||
let command_line = lines.next().expect("each string has at least one line");
|
let command = lines.next().expect("each string has at least one line");
|
||||||
let body = lines.collect::<Vec<_>>();
|
let body = lines.collect::<Vec<_>>();
|
||||||
|
let parsed = match parse_admin_command(command) {
|
||||||
let admin_command = match parse_admin_command(command_line) {
|
Ok(parsed) => parsed,
|
||||||
Ok(command) => command,
|
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
let server_name = services().globals.server_name();
|
let server_name = services().globals.server_name();
|
||||||
let message = error.replace("server.name", server_name.as_str());
|
let message = error.replace("server.name", server_name.as_str());
|
||||||
|
@ -96,12 +97,15 @@ async fn process_admin_message(msg: String) -> CommandOutput {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
match process_admin_command(admin_command, body).await {
|
let timer = Instant::now();
|
||||||
Ok(reply_message) => Some(reply_message),
|
let result = process_admin_command(parsed, body).await;
|
||||||
Err(error) => {
|
let elapsed = timer.elapsed();
|
||||||
let markdown_message = format!("Encountered an error while handling the command:\n```\n{error}\n```",);
|
conduit::debug!(?command, ok = result.is_ok(), "command processed in {elapsed:?}");
|
||||||
Some(RoomMessageEventContent::notice_markdown(markdown_message))
|
match result {
|
||||||
},
|
Ok(reply) => Some(reply),
|
||||||
|
Err(error) => Some(RoomMessageEventContent::notice_markdown(format!(
|
||||||
|
"Encountered an error while handling the command:\n```\n{error}\n```"
|
||||||
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue