2024-04-13 16:16:09 +01:00
|
|
|
// crate::server::actors::webhook
|
|
|
|
|
|
|
|
mod message;
|
|
|
|
mod router;
|
|
|
|
mod server;
|
|
|
|
|
|
|
|
use actix::prelude::*;
|
|
|
|
|
|
|
|
pub use message::WebhookMessage;
|
|
|
|
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-04 12:37:35 +01:00
|
|
|
span: tracing::Span,
|
2024-04-13 16:16:09 +01:00
|
|
|
spawn_handle: Option<actix::SpawnHandle>,
|
|
|
|
message_receiver: Recipient<WebhookMessage>,
|
|
|
|
}
|
|
|
|
impl WebhookActor {
|
2024-05-04 12:37:35 +01:00
|
|
|
pub fn new(message_receiver: Recipient<WebhookMessage>) -> Self {
|
|
|
|
let span = tracing::info_span!("WebhookActor");
|
2024-04-13 16:16:09 +01:00
|
|
|
Self {
|
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-04-13 16:16:09 +01:00
|
|
|
let address: Recipient<WebhookMessage> = self.message_receiver.clone();
|
|
|
|
let server = server::start(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);
|
|
|
|
}
|
|
|
|
}
|