fix: report verified orbit capture outcomes

This commit is contained in:
2026-11-09 22:01:14 +07:00
parent e95d1553ff
commit 2129e80c38
6 changed files with 128 additions and 32 deletions

View File

@@ -6,16 +6,32 @@ use tessera_core::manifest::SnapshotManifest;
use tessera_providers::provider_from_config;
use uuid::Uuid;
pub async fn run_orbit_internal(state: HubState, orbit_id: Uuid) -> Result<()> {
pub async fn run_orbit_internal(state: HubState, orbit_id: Uuid) -> Result<Option<Uuid>> {
let orbits = state.db.list_orbits().await?;
let orbit = orbits
.into_iter()
.find(|o| o.id == orbit_id)
.context("orbit not found")?;
run_orbit_row(state, orbit).await
anyhow::ensure!(
state.active_orbits.lock().await.insert(orbit_id),
"orbit already running"
);
// Keep capture and its status update together if the requesting client disconnects.
tokio::spawn(async move {
let result = run_orbit_row(&state, orbit).await;
if result.is_err() {
if let Err(error) = state.db.set_orbit_status(orbit_id, "failed").await {
tracing::error!(%orbit_id, %error, "could not record failed capture");
}
}
state.active_orbits.lock().await.remove(&orbit_id);
result
})
.await?
}
pub async fn run_orbit_row(state: HubState, orbit: OrbitRow) -> Result<()> {
async fn run_orbit_row(state: &HubState, orbit: OrbitRow) -> Result<Option<Uuid>> {
state.db.set_orbit_status(orbit.id, "running").await?;
let provider_kind = match orbit.provider.as_str() {
@@ -42,13 +58,16 @@ pub async fn run_orbit_row(state: HubState, orbit: OrbitRow) -> Result<()> {
.snapshot(manifest, &capture.payload, orbit.dry_run)
.context("vault snapshot")?;
if !orbit.dry_run {
let _pruned = vault.prune_with_decay(&orbit.decay_preset)?;
let retained_snapshot = if orbit.dry_run {
None
} else {
let pruned = vault.prune_orbit_with_decay(orbit.id, &orbit.decay_preset)?;
state
.db
.audit("decay.pruned", &format!("orbit={}", orbit.name))
.await?;
}
(!pruned.contains(&snap.id)).then_some(snap.id)
};
let status = if orbit.dry_run {
"rehearsed"
@@ -67,5 +86,5 @@ pub async fn run_orbit_row(state: HubState, orbit: OrbitRow) -> Result<()> {
&format!("snapshot={}", snap.id),
)
.await?;
Ok(())
Ok(retained_snapshot)
}