forked from kemitix/git-next
35 lines
899 B
Rust
35 lines
899 B
Rust
|
// 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;
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
pub struct WebhookActor {
|
||
|
spawn_handle: Option<actix::SpawnHandle>,
|
||
|
message_receiver: Recipient<WebhookMessage>,
|
||
|
}
|
||
|
impl WebhookActor {
|
||
|
pub const fn new(message_receiver: Recipient<WebhookMessage>) -> Self {
|
||
|
Self {
|
||
|
message_receiver,
|
||
|
spawn_handle: None,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
impl Actor for WebhookActor {
|
||
|
type Context = actix::Context<Self>;
|
||
|
fn started(&mut self, ctx: &mut Self::Context) {
|
||
|
let address: Recipient<WebhookMessage> = self.message_receiver.clone();
|
||
|
let server = server::start(address);
|
||
|
let spawn_handle = ctx.spawn(server.into_actor(self));
|
||
|
self.spawn_handle.replace(spawn_handle);
|
||
|
}
|
||
|
}
|