add (probably messy) support for hot lib reload via admin command

`!admin test test1`

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-28 18:29:48 -04:00 committed by June
parent 76c5942b4f
commit b282c1eb6d
6 changed files with 66 additions and 1 deletions

View file

@ -27,6 +27,9 @@ use tokio::sync::{Mutex, MutexGuard};
use tracing::{error, warn};
use self::fsck::FsckCommand;
#[cfg(feature = "hot_reload")]
#[allow(unused_imports)]
use self::test_cmd::TestCommands;
use super::pdu::PduBuilder;
use crate::{
service::admin::{
@ -44,6 +47,9 @@ pub(crate) mod media;
pub(crate) mod query;
pub(crate) mod room;
pub(crate) mod server;
#[cfg(feature = "hot_reload")]
#[allow(unused_imports)]
pub(crate) mod test_cmd;
pub(crate) mod user;
const PAGE_SIZE: usize = 100;
@ -87,6 +93,10 @@ enum AdminCommand {
#[command(subcommand)]
/// - Query all the database getters and iterators
Fsck(FsckCommand),
#[cfg(feature = "hot_reload")]
#[command(subcommand)]
Test(TestCommands),
}
#[derive(Debug)]
@ -304,6 +314,8 @@ impl Service {
AdminCommand::Debug(command) => debug::process(command, body).await?,
AdminCommand::Query(command) => query::process(command, body).await?,
AdminCommand::Fsck(command) => fsck::process(command, body).await?,
#[cfg(feature = "hot_reload")]
AdminCommand::Test(command) => test_cmd::process(command, body).await?,
};
Ok(reply_message_content)

View file

@ -0,0 +1,31 @@
use clap::Subcommand;
#[cfg(feature = "hot_reload")]
#[allow(unused_imports)]
#[allow(clippy::wildcard_imports)]
use hot_lib::*;
use ruma::events::room::message::RoomMessageEventContent;
use crate::{debug_error, Result};
#[cfg(feature = "hot_reload")]
#[hot_lib_reloader::hot_module(dylib = "lib")]
mod hot_lib {
hot_functions_from_file!("lib/src/lib.rs");
}
#[cfg_attr(test, derive(Debug))]
#[derive(Subcommand)]
pub(crate) enum TestCommands {
Test1,
}
pub(crate) async fn process(command: TestCommands, _body: Vec<&str>) -> Result<RoomMessageEventContent> {
Ok(match command {
TestCommands::Test1 => {
debug_error!("before calling test_command");
test_command();
debug_error!("after calling test_command");
RoomMessageEventContent::notice_plain(String::from("loaded"))
},
})
}