From 8f95ae0058a9f426c5d3f8f96990f6b0eb358b9e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 19 Jul 2024 07:48:36 +0100 Subject: [PATCH] refactor: extract messages and handlers modules from webhook-actor --- crates/webhook-actor/Cargo.toml | 1 + crates/webhook-actor/src/handlers/mod.rs | 1 + .../src/handlers/shutdown_webhook.rs | 13 +++++++++++++ crates/webhook-actor/src/lib.rs | 15 +++------------ crates/webhook-actor/src/messages.rs | 4 ++++ 5 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 crates/webhook-actor/src/handlers/mod.rs create mode 100644 crates/webhook-actor/src/handlers/shutdown_webhook.rs create mode 100644 crates/webhook-actor/src/messages.rs diff --git a/crates/webhook-actor/Cargo.toml b/crates/webhook-actor/Cargo.toml index f50dafa..353e7fc 100644 --- a/crates/webhook-actor/Cargo.toml +++ b/crates/webhook-actor/Cargo.toml @@ -7,6 +7,7 @@ repository = { workspace = true } description = "webhook actor for git-next, the trunk-based development manager" [dependencies] +git-next-actor-macros = { workspace = true } git-next-config = { workspace = true } git-next-repo-actor = { workspace = true } diff --git a/crates/webhook-actor/src/handlers/mod.rs b/crates/webhook-actor/src/handlers/mod.rs new file mode 100644 index 0000000..418e9f6 --- /dev/null +++ b/crates/webhook-actor/src/handlers/mod.rs @@ -0,0 +1 @@ +mod shutdown_webhook; diff --git a/crates/webhook-actor/src/handlers/shutdown_webhook.rs b/crates/webhook-actor/src/handlers/shutdown_webhook.rs new file mode 100644 index 0000000..79a1705 --- /dev/null +++ b/crates/webhook-actor/src/handlers/shutdown_webhook.rs @@ -0,0 +1,13 @@ +// +use actix::prelude::*; + +use crate::{ShutdownWebhook, WebhookActor}; + +impl Handler for WebhookActor { + type Result = (); + + fn handle(&mut self, _msg: ShutdownWebhook, ctx: &mut Self::Context) -> Self::Result { + self.spawn_handle.take(); + ctx.stop(); + } +} diff --git a/crates/webhook-actor/src/lib.rs b/crates/webhook-actor/src/lib.rs index cf37e0d..cf670cf 100644 --- a/crates/webhook-actor/src/lib.rs +++ b/crates/webhook-actor/src/lib.rs @@ -1,10 +1,13 @@ // use actix::prelude::*; +mod handlers; +pub mod messages; mod router; mod server; use git_next_repo_actor::messages::WebhookNotification; +pub use messages::ShutdownWebhook; use std::net::SocketAddr; @@ -40,15 +43,3 @@ impl Actor for WebhookActor { self.spawn_handle.replace(spawn_handle); } } - -#[derive(Debug, Message)] -#[rtype(result = "()")] -pub struct ShutdownWebhook; -impl Handler for WebhookActor { - type Result = (); - - fn handle(&mut self, _msg: ShutdownWebhook, ctx: &mut Self::Context) -> Self::Result { - self.spawn_handle.take(); - ctx.stop(); - } -} diff --git a/crates/webhook-actor/src/messages.rs b/crates/webhook-actor/src/messages.rs new file mode 100644 index 0000000..97cf082 --- /dev/null +++ b/crates/webhook-actor/src/messages.rs @@ -0,0 +1,4 @@ +// +use git_next_actor_macros::message; + +message!(ShutdownWebhook: "Request to shutdown the Webhook actor");