diff --git a/crates/server-actor/src/handlers/mod.rs b/crates/server-actor/src/handlers/mod.rs index 4c189e55..c92aeeb5 100644 --- a/crates/server-actor/src/handlers/mod.rs +++ b/crates/server-actor/src/handlers/mod.rs @@ -1,3 +1,4 @@ mod file_updated; mod receive_server_config; mod receive_valid_server_config; +mod shutdown; diff --git a/crates/server-actor/src/handlers/shutdown.rs b/crates/server-actor/src/handlers/shutdown.rs new file mode 100644 index 00000000..24bb4689 --- /dev/null +++ b/crates/server-actor/src/handlers/shutdown.rs @@ -0,0 +1,15 @@ +//- +use actix::prelude::*; +use git_next_webhook_actor::ShutdownWebhook; + +use crate::{messages::Shutdown, Server}; + +impl Handler for Server { + type Result = (); + + fn handle(&mut self, _msg: Shutdown, _ctx: &mut Self::Context) -> Self::Result { + if let Some(webhook) = self.webhook.take() { + webhook.do_send(ShutdownWebhook); + } + } +} diff --git a/crates/server-actor/src/lib.rs b/crates/server-actor/src/lib.rs index d04ff5b4..adea3458 100644 --- a/crates/server-actor/src/lib.rs +++ b/crates/server-actor/src/lib.rs @@ -3,7 +3,7 @@ mod tests; mod handlers; -mod messages; +pub mod messages; use actix::prelude::*; use git_next_config as config; diff --git a/crates/server-actor/src/messages.rs b/crates/server-actor/src/messages.rs index c7f8f71a..adbf46e7 100644 --- a/crates/server-actor/src/messages.rs +++ b/crates/server-actor/src/messages.rs @@ -19,3 +19,5 @@ pub struct ValidServerConfig { pub server_storage: ServerStorage, } message!(ReceiveValidServerConfig: ValidServerConfig: "Notification of validated server configuration."); + +message!(Shutdown: "Notification to shutdown the server actor"); diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index 601b0aeb..3dee926e 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -44,7 +44,7 @@ pub fn start( server.do_send(FileUpdated); info!("Starting File Watcher..."); - let fw = match FileWatcher::new("git-next-server.toml".into(), server.recipient()) { + let fw = match FileWatcher::new("git-next-server.toml".into(), server.clone().recipient()) { Ok(fw) => fw, Err(err) => { error!(?err, "Failed to start file watcher"); @@ -56,6 +56,7 @@ pub fn start( info!("Server running - Press Ctrl-C to stop..."); let _ = actix_rt::signal::ctrl_c().await; info!("Ctrl-C received, shutting down..."); + server.do_send(git_next_server_actor::messages::Shutdown); System::current().stop(); }; let system = System::new();