mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 21:21:32 +00:00
krata: implement event notifications
This commit is contained in:
@ -2,28 +2,39 @@ use std::{net::SocketAddr, path::PathBuf, str::FromStr};
|
||||
|
||||
use anyhow::Result;
|
||||
use control::RuntimeControlService;
|
||||
use event::{DaemonEventContext, DaemonEventGenerator};
|
||||
use krata::{control::control_service_server::ControlServiceServer, dial::ControlDialAddress};
|
||||
use log::info;
|
||||
use runtime::Runtime;
|
||||
use tokio::net::UnixListener;
|
||||
use tokio::{net::UnixListener, task::JoinHandle};
|
||||
use tokio_stream::wrappers::UnixListenerStream;
|
||||
use tonic::transport::{Identity, Server, ServerTlsConfig};
|
||||
|
||||
pub mod control;
|
||||
pub mod event;
|
||||
pub mod runtime;
|
||||
|
||||
pub struct Daemon {
|
||||
store: String,
|
||||
runtime: Runtime,
|
||||
events: DaemonEventContext,
|
||||
task: JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl Daemon {
|
||||
pub async fn new(store: String, runtime: Runtime) -> Result<Self> {
|
||||
Ok(Self { store, runtime })
|
||||
let runtime_for_events = runtime.dupe().await?;
|
||||
let (events, generator) = DaemonEventGenerator::new(runtime_for_events).await?;
|
||||
Ok(Self {
|
||||
store,
|
||||
runtime,
|
||||
events,
|
||||
task: generator.launch().await?,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn listen(&mut self, addr: ControlDialAddress) -> Result<()> {
|
||||
let control_service = RuntimeControlService::new(self.runtime.clone());
|
||||
let control_service = RuntimeControlService::new(self.events.clone(), self.runtime.clone());
|
||||
|
||||
let mut server = Server::builder();
|
||||
|
||||
@ -72,3 +83,9 @@ impl Daemon {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Daemon {
|
||||
fn drop(&mut self) {
|
||||
self.task.abort();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user