18 lines
583 B
Rust
18 lines
583 B
Rust
use std::{sync::Arc, time::Duration};
|
|
|
|
use axum::{Router, extract::State, http::StatusCode, routing::get};
|
|
|
|
pub fn router(db: database::Connection) -> Router {
|
|
Router::new()
|
|
.route("/healthz", get(|| async { StatusCode::NO_CONTENT }))
|
|
.route("/readyz", get(readiness))
|
|
.with_state(Arc::new(db))
|
|
}
|
|
|
|
async fn readiness(State(db): State<Arc<database::Connection>>) -> StatusCode {
|
|
match tokio::time::timeout(Duration::from_secs(2), db.revision()).await {
|
|
Ok(Ok(_)) => StatusCode::NO_CONTENT,
|
|
_ => StatusCode::SERVICE_UNAVAILABLE,
|
|
}
|
|
}
|