git-next/src/server/actors/webhook/mod.rs

40 lines
1 KiB
Rust
Raw Normal View History

// 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;
use tracing::Instrument;
#[derive(Debug)]
pub struct WebhookActor {
span: tracing::Span,
spawn_handle: Option<actix::SpawnHandle>,
message_receiver: Recipient<WebhookMessage>,
}
impl WebhookActor {
pub fn new(message_receiver: Recipient<WebhookMessage>) -> Self {
let span = tracing::info_span!("WebhookActor");
Self {
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<WebhookMessage> = self.message_receiver.clone();
let server = server::start(address);
let spawn_handle = ctx.spawn(server.in_current_span().into_actor(self));
self.spawn_handle.replace(spawn_handle);
}
}