fix: report verified orbit capture outcomes
This commit is contained in:
@@ -2,9 +2,9 @@ use crate::db::OrbitRow;
|
||||
use crate::state::{HubState, PairingEntry};
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
http::{header, StatusCode, Uri},
|
||||
http::{header, HeaderMap, HeaderValue, StatusCode, Uri},
|
||||
response::IntoResponse,
|
||||
routing::{delete, get, post},
|
||||
routing::{get, post},
|
||||
Json, Router,
|
||||
};
|
||||
use base64::Engine;
|
||||
@@ -49,6 +49,7 @@ struct ApiDoc;
|
||||
#[derive(serde::Serialize, utoipa::ToSchema)]
|
||||
struct SnapshotSummary {
|
||||
id: Uuid,
|
||||
orbit_id: Uuid,
|
||||
taken_at: chrono::DateTime<chrono::Utc>,
|
||||
orbit_name: String,
|
||||
size_bytes: u64,
|
||||
@@ -147,6 +148,7 @@ async fn list_snapshots(State(state): State<HubState>) -> Result<Json<Vec<Snapsh
|
||||
.into_iter()
|
||||
.map(|s| SnapshotSummary {
|
||||
id: s.id,
|
||||
orbit_id: s.manifest.orbit_id,
|
||||
taken_at: s.taken_at,
|
||||
orbit_name: s.manifest.orbit_name,
|
||||
size_bytes: s.size_bytes,
|
||||
@@ -186,15 +188,24 @@ async fn create_orbit(
|
||||
Ok(Json(row))
|
||||
}
|
||||
|
||||
#[utoipa::path(post, path = "/api/v1/orbits/{id}/run", params(("id" = Uuid, Path, description = "orbit id")), responses((status = 204)))]
|
||||
#[utoipa::path(post, path = "/api/v1/orbits/{id}/run", params(("id" = Uuid, Path, description = "orbit id")), responses((status = 204, headers(("X-Tessera-Snapshot-Id" = Uuid, description = "New retained snapshot ID when a capture writes to the vault")))))]
|
||||
async fn trigger_orbit(
|
||||
State(state): State<HubState>,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<StatusCode, StatusCode> {
|
||||
crate::api::run_orbit_internal(state, id)
|
||||
) -> Result<(StatusCode, HeaderMap), StatusCode> {
|
||||
let snapshot_id = crate::api::run_orbit_internal(state, id)
|
||||
.await
|
||||
.map(|_| StatusCode::NO_CONTENT)
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.map_err(|error| {
|
||||
tracing::warn!(orbit_id = %id, %error, "capture did not complete");
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
let mut headers = HeaderMap::new();
|
||||
if let Some(snapshot_id) = snapshot_id {
|
||||
let value = HeaderValue::from_str(&snapshot_id.to_string())
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
headers.insert("x-tessera-snapshot-id", value);
|
||||
}
|
||||
Ok((StatusCode::NO_CONTENT, headers))
|
||||
}
|
||||
|
||||
#[utoipa::path(post, path = "/api/v1/reconstitute", request_body = ReconstituteRequest, responses((status = 200, body = ReconstituteStartResponse)))]
|
||||
@@ -230,21 +241,14 @@ async fn start_reconstitute(
|
||||
}
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
}
|
||||
let aborted = {
|
||||
let map = state_bg.reconstitute_sessions.read().await;
|
||||
map.get(&session_id)
|
||||
.map(|s| s.state == ReconstituteState::Aborted)
|
||||
.unwrap_or(true)
|
||||
};
|
||||
if aborted {
|
||||
return;
|
||||
}
|
||||
{
|
||||
let mut map = state_bg.reconstitute_sessions.write().await;
|
||||
if let Some(s) = map.get_mut(&session_id) {
|
||||
s.state = ReconstituteState::Restoring;
|
||||
s.seconds_remaining = 0;
|
||||
let Some(s) = map.get_mut(&session_id) else { return };
|
||||
if s.state == ReconstituteState::Aborted {
|
||||
return;
|
||||
}
|
||||
s.state = ReconstituteState::Restoring;
|
||||
s.seconds_remaining = 0;
|
||||
}
|
||||
let dest = std::path::PathBuf::from(&target);
|
||||
let result = {
|
||||
|
||||
Reference in New Issue
Block a user