Paul Campbell
8f95ae0058
All checks were successful
Rust / build (push) Successful in 1m54s
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/cron-docker-builder 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
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
//
|
|
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;
|
|
|
|
pub use router::AddWebhookRecipient;
|
|
pub use router::WebhookRouter;
|
|
use tracing::Instrument;
|
|
|
|
#[derive(Debug)]
|
|
pub struct WebhookActor {
|
|
socket_addr: SocketAddr,
|
|
span: tracing::Span,
|
|
spawn_handle: Option<actix::SpawnHandle>,
|
|
message_receiver: Recipient<WebhookNotification>,
|
|
}
|
|
impl WebhookActor {
|
|
pub fn new(socket_addr: SocketAddr, message_receiver: Recipient<WebhookNotification>) -> Self {
|
|
let span = tracing::info_span!("WebhookActor");
|
|
Self {
|
|
socket_addr,
|
|
span,
|
|
message_receiver,
|
|
spawn_handle: None,
|
|
}
|
|
}
|
|
}
|
|
impl Actor for WebhookActor {
|
|
type Context = actix::Context<Self>;
|
|
fn started(&mut self, ctx: &mut Self::Context) {
|
|
let _gaurd = self.span.enter();
|
|
let address: Recipient<WebhookNotification> = self.message_receiver.clone();
|
|
let server = server::start(self.socket_addr, address);
|
|
let spawn_handle = ctx.spawn(server.in_current_span().into_actor(self));
|
|
self.spawn_handle.replace(spawn_handle);
|
|
}
|
|
}
|