feat: perform controlled shutdown on ctrl-c
All checks were successful
Rust / build (push) Successful in 1m50s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
All checks were successful
Rust / build (push) Successful in 1m50s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
Closes kemitix/git-next#94 Controlled shutdown includes attempting to unregister webhooks.
This commit is contained in:
parent
681b2c4c10
commit
fd762e2bd2
5 changed files with 21 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
mod file_updated;
|
mod file_updated;
|
||||||
mod receive_server_config;
|
mod receive_server_config;
|
||||||
mod receive_valid_server_config;
|
mod receive_valid_server_config;
|
||||||
|
mod shutdown;
|
||||||
|
|
15
crates/server-actor/src/handlers/shutdown.rs
Normal file
15
crates/server-actor/src/handlers/shutdown.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
//-
|
||||||
|
use actix::prelude::*;
|
||||||
|
use git_next_webhook_actor::ShutdownWebhook;
|
||||||
|
|
||||||
|
use crate::{messages::Shutdown, Server};
|
||||||
|
|
||||||
|
impl Handler<Shutdown> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
mod handlers;
|
mod handlers;
|
||||||
mod messages;
|
pub mod messages;
|
||||||
|
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use git_next_config as config;
|
use git_next_config as config;
|
||||||
|
|
|
@ -19,3 +19,5 @@ pub struct ValidServerConfig {
|
||||||
pub server_storage: ServerStorage,
|
pub server_storage: ServerStorage,
|
||||||
}
|
}
|
||||||
message!(ReceiveValidServerConfig: ValidServerConfig: "Notification of validated server configuration.");
|
message!(ReceiveValidServerConfig: ValidServerConfig: "Notification of validated server configuration.");
|
||||||
|
|
||||||
|
message!(Shutdown: "Notification to shutdown the server actor");
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub fn start(
|
||||||
server.do_send(FileUpdated);
|
server.do_send(FileUpdated);
|
||||||
|
|
||||||
info!("Starting File Watcher...");
|
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,
|
Ok(fw) => fw,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(?err, "Failed to start file watcher");
|
error!(?err, "Failed to start file watcher");
|
||||||
|
@ -56,6 +56,7 @@ pub fn start(
|
||||||
info!("Server running - Press Ctrl-C to stop...");
|
info!("Server running - Press Ctrl-C to stop...");
|
||||||
let _ = actix_rt::signal::ctrl_c().await;
|
let _ = actix_rt::signal::ctrl_c().await;
|
||||||
info!("Ctrl-C received, shutting down...");
|
info!("Ctrl-C received, shutting down...");
|
||||||
|
server.do_send(git_next_server_actor::messages::Shutdown);
|
||||||
System::current().stop();
|
System::current().stop();
|
||||||
};
|
};
|
||||||
let system = System::new();
|
let system = System::new();
|
||||||
|
|
Loading…
Reference in a new issue