adds saving and loading history to and from disk
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user