v0.14.2-connectivity
This commit is contained in:
@@ -46,6 +46,15 @@ pub fn start(state: AppState) {
|
||||
home_assistant_energy_loop(ha_energy_state).await;
|
||||
});
|
||||
|
||||
let local_connectivity_state = state.clone();
|
||||
tokio::spawn(async move {
|
||||
local_connectivity_loop(local_connectivity_state).await;
|
||||
});
|
||||
let cloud_connectivity_state = state.clone();
|
||||
tokio::spawn(async move {
|
||||
cloud_connectivity_loop(cloud_connectivity_state).await;
|
||||
});
|
||||
|
||||
let control_plan_state = state.clone();
|
||||
tokio::spawn(async move {
|
||||
control_plan_cache_loop(control_plan_state).await;
|
||||
@@ -139,6 +148,11 @@ pub fn start(state: AppState) {
|
||||
Ok(_) => {}
|
||||
Err(err) => tracing::warn!(error=?err, "cannot compact history"),
|
||||
}
|
||||
match maintenance_state.db.compact_network_history(compaction_days) {
|
||||
Ok(count) if count > 0 => tracing::info!(count, "connectivity history samples compacted"),
|
||||
Ok(_) => {}
|
||||
Err(err) => tracing::warn!(error=?err, "cannot compact connectivity history"),
|
||||
}
|
||||
}
|
||||
if settings.influxdb.enabled {
|
||||
match archive_old_history(
|
||||
@@ -172,6 +186,13 @@ pub fn start(state: AppState) {
|
||||
Ok(_) => {}
|
||||
Err(err) => tracing::warn!(error=?err, "cannot prune energy readings"),
|
||||
}
|
||||
match maintenance_state.db.prune_network_readings(retention_days) {
|
||||
Ok(count) if count > 0 => {
|
||||
tracing::info!(count, retention_days, "old connectivity readings pruned")
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(err) => tracing::warn!(error=?err, "cannot prune connectivity readings"),
|
||||
}
|
||||
}
|
||||
let event_retention_days = settings.event_log_retention_days.max(1) as i64;
|
||||
match maintenance_state.db.prune_events(event_retention_days) {
|
||||
@@ -216,5 +237,17 @@ async fn archive_old_history(state: &AppState, threshold_days: u32) -> Result<u6
|
||||
break;
|
||||
}
|
||||
}
|
||||
for _ in 0..50 {
|
||||
let network = state.db.network_before(cutoff, 1_000)?;
|
||||
if network.is_empty() {
|
||||
break;
|
||||
}
|
||||
influxdb::write_network_batch(&state.http, &settings, &network).await?;
|
||||
let deleted = state.db.delete_network_batch(&network)?;
|
||||
moved += deleted;
|
||||
if deleted == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(moved)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user