feat: added live updates for checking in

This commit is contained in:
Andrew Rioux
2025-02-22 20:30:32 -05:00
parent f284cf47eb
commit e103fa9f28
6 changed files with 62 additions and 16 deletions

View File

@@ -12,6 +12,7 @@ pub enum Error {
Rustls(rustls::Error),
Rcgen(rcgen::Error),
WebPki(rustls::client::VerifierBuilderError),
TokioSend,
}
impl std::fmt::Display for Error {
@@ -38,6 +39,9 @@ impl std::fmt::Display for Error {
Error::WebPki(err) => {
write!(f, "webpki error: {err:?}")
}
Error::TokioSend => {
write!(f, "tokio broadcast error")
}
}
}
}
@@ -105,3 +109,9 @@ impl From<rustls::client::VerifierBuilderError> for Error {
Self::WebPki(err)
}
}
impl<T> From<tokio::sync::broadcast::error::SendError<T>> for Error {
fn from(_: tokio::sync::broadcast::error::SendError<T>) -> Self {
Self::TokioSend
}
}

View File

@@ -107,9 +107,7 @@ pub async fn start_listener(
.fetch_one(&db)
.await?;
let sender = broadcast::Sender::new(128);
let app = router::get_router(db, sender.clone());
let app = router::get_router(db, beacon_event_broadcast.clone());
let ca_cert = rustls::pki_types::CertificateDer::from(listener.certificate.clone());
@@ -182,7 +180,7 @@ pub async fn start_listener(
));
};
blm_handle.insert(listener_id, BeaconListenerHandle { join_handle, events_broadcast: sender });
blm_handle.insert(listener_id, BeaconListenerHandle { join_handle, events_broadcast: beacon_event_broadcast });
Ok(())
}

View File

@@ -76,6 +76,8 @@ pub async fn handle_checkin(
let current_beacon_reg = match current_beacon_reg {
Some(rec) => {
state.event_publisher.send(BeaconEvent::Checkin(reg.beacon_id.clone()))?;
parse_db_config(rec)
},
None => {
@@ -111,6 +113,8 @@ pub async fn handle_checkin(
.fetch_one(&state.db)
.await?;
state.event_publisher.send(BeaconEvent::NewBeacon(reg.beacon_id.clone()))?;
parse_db_config(rec)
}
};