adds saving and loading history to and from disk

This commit is contained in:
2025-01-01 10:08:50 -05:00
parent dfd524ba19
commit 9136c5fd71
15 changed files with 602 additions and 146 deletions

View File

@@ -9,11 +9,11 @@ pub mod core {
use crate::telemetry::history::TelemetryHistoryService;
use crate::telemetry::management_service::TelemetryManagementService;
use std::error::Error;
use std::sync::Arc;
use log::error;
use tokio_util::sync::CancellationToken;
pub async fn setup() -> Result<(), Box<dyn Error>> {
pub async fn setup() -> anyhow::Result<()> {
let cancellation_token = CancellationToken::new();
{
let cancellation_token = cancellation_token.clone();
@@ -24,15 +24,23 @@ pub async fn setup() -> Result<(), Box<dyn Error>> {
}
let tlm = Arc::new(TelemetryManagementService::new(
TelemetryHistoryService::new(),
));
TelemetryHistoryService::new()?,
)?);
let grpc_server = grpc::setup(cancellation_token.clone(), tlm.clone())?;
let result = http::setup(cancellation_token.clone(), tlm).await;
let result = http::setup(cancellation_token.clone(), tlm.clone()).await;
cancellation_token.cancel();
result?;
grpc_server.await?;
result?; // result is dropped
grpc_server.await?; //grpc server is dropped
drop(cancellation_token); // All cancellation tokens are now dropped
// Perform cleanup functions - at this point all servers have stopped and we can be sure that cleaning things up is safe
if let Some(tlm) = Arc::into_inner(tlm) {
tlm.cleanup().await?;
} else {
error!("Could not clean up Telemetry Management Service. Arc not released.")
}
Ok(())
}