fix(openapi): harden story 2.1 production lifecycle
This commit is contained in:
@@ -24,23 +24,89 @@ pub async fn health() -> Json<serde_json::Value> {
|
||||
}
|
||||
|
||||
pub async fn readiness(State(state): State<AppState>) -> impl IntoResponse {
|
||||
match state.service.readiness().await {
|
||||
Ok(()) => (
|
||||
let checks = state.service.readiness().await;
|
||||
let postgres = if checks.postgres {
|
||||
"ready"
|
||||
} else {
|
||||
"not_ready"
|
||||
};
|
||||
let artifact_storage = if checks.artifact_storage {
|
||||
"ready"
|
||||
} else {
|
||||
"not_ready"
|
||||
};
|
||||
if checks.is_ready() {
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(json!({
|
||||
"service": "admin-api",
|
||||
"status": "ready",
|
||||
"checks": { "postgres": "ready" }
|
||||
"checks": { "postgres": postgres, "artifact_storage": artifact_storage }
|
||||
})),
|
||||
),
|
||||
Err(error) => (
|
||||
)
|
||||
} else {
|
||||
(
|
||||
StatusCode::SERVICE_UNAVAILABLE,
|
||||
Json(json!({
|
||||
"service": "admin-api",
|
||||
"status": "not_ready",
|
||||
"checks": { "postgres": "not_ready" },
|
||||
"error": error.to_string()
|
||||
"checks": { "postgres": postgres, "artifact_storage": artifact_storage }
|
||||
})),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::service::ReadinessChecks;
|
||||
|
||||
#[test]
|
||||
fn readiness_checks_identify_a_postgres_failure() {
|
||||
let checks = ReadinessChecks {
|
||||
postgres: false,
|
||||
artifact_storage: true,
|
||||
};
|
||||
assert!(!checks.is_ready());
|
||||
assert_eq!(
|
||||
if checks.postgres {
|
||||
"ready"
|
||||
} else {
|
||||
"not_ready"
|
||||
},
|
||||
"not_ready"
|
||||
);
|
||||
assert_eq!(
|
||||
if checks.artifact_storage {
|
||||
"ready"
|
||||
} else {
|
||||
"not_ready"
|
||||
},
|
||||
"ready"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn readiness_checks_identify_an_artifact_storage_failure() {
|
||||
let checks = ReadinessChecks {
|
||||
postgres: true,
|
||||
artifact_storage: false,
|
||||
};
|
||||
assert!(!checks.is_ready());
|
||||
assert_eq!(
|
||||
if checks.postgres {
|
||||
"ready"
|
||||
} else {
|
||||
"not_ready"
|
||||
},
|
||||
"ready"
|
||||
);
|
||||
assert_eq!(
|
||||
if checks.artifact_storage {
|
||||
"ready"
|
||||
} else {
|
||||
"not_ready"
|
||||
},
|
||||
"not_ready"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user