2024-06-29 08:20:56 +01:00
|
|
|
//
|
2024-05-25 11:25:13 +01:00
|
|
|
use actix::prelude::*;
|
2024-04-13 16:16:09 +01:00
|
|
|
|
2024-07-19 07:48:36 +01:00
|
|
|
mod handlers;
|
|
|
|
pub mod messages;
|
2024-04-13 16:16:09 +01:00
|
|
|
mod router;
|
|
|
|
mod server;
|
|
|
|
|
2024-06-19 07:03:08 +01:00
|
|
|
use git_next_repo_actor::messages::WebhookNotification;
|
2024-07-19 07:48:36 +01:00
|
|
|
pub use messages::ShutdownWebhook;
|
2024-05-10 22:01:47 +01:00
|
|
|
|
2024-05-25 11:25:13 +01:00
|
|
|
use std::net::SocketAddr;
|
2024-04-13 16:16:09 +01:00
|
|
|
|
|
|
|
pub use router::AddWebhookRecipient;
|
|
|
|
pub use router::WebhookRouter;
|
2024-05-04 12:37:35 +01:00
|
|
|
use tracing::Instrument;
|
2024-04-13 16:16:09 +01:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct WebhookActor {
|
2024-05-10 22:01:47 +01:00
|
|
|
socket_addr: SocketAddr,
|
2024-05-04 12:37:35 +01:00
|
|
|
span: tracing::Span,
|
2024-04-13 16:16:09 +01:00
|
|
|
spawn_handle: Option<actix::SpawnHandle>,
|
2024-06-19 07:03:08 +01:00
|
|
|
message_receiver: Recipient<WebhookNotification>,
|
2024-04-13 16:16:09 +01:00
|
|
|
}
|
|
|
|
impl WebhookActor {
|
2024-06-19 07:03:08 +01:00
|
|
|
pub fn new(socket_addr: SocketAddr, message_receiver: Recipient<WebhookNotification>) -> Self {
|
2024-05-04 12:37:35 +01:00
|
|
|
let span = tracing::info_span!("WebhookActor");
|
2024-04-13 16:16:09 +01:00
|
|
|
Self {
|
2024-05-10 22:01:47 +01:00
|
|
|
socket_addr,
|
2024-05-04 12:37:35 +01:00
|
|
|
span,
|
2024-04-13 16:16:09 +01:00
|
|
|
message_receiver,
|
|
|
|
spawn_handle: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Actor for WebhookActor {
|
|
|
|
type Context = actix::Context<Self>;
|
|
|
|
fn started(&mut self, ctx: &mut Self::Context) {
|
2024-05-04 12:37:35 +01:00
|
|
|
let _gaurd = self.span.enter();
|
2024-06-19 07:03:08 +01:00
|
|
|
let address: Recipient<WebhookNotification> = self.message_receiver.clone();
|
2024-05-10 22:01:47 +01:00
|
|
|
let server = server::start(self.socket_addr, address);
|
2024-05-04 12:37:35 +01:00
|
|
|
let spawn_handle = ctx.spawn(server.in_current_span().into_actor(self));
|
2024-04-13 16:16:09 +01:00
|
|
|
self.spawn_handle.replace(spawn_handle);
|
|
|
|
}
|
|
|
|
}
|