Our Personal Data Server from scratch! tranquil.farm
oauth atproto pds rust postgresql objectstorage fun

feat: add version information to _health endpoint

authored by diddyfo.id and committed by tangled.org 1e02c580 e2f26c25

+25 -13
+14 -3
crates/tranquil-pds/src/api/server/meta.rs
··· 1 + use crate::BUILD_VERSION; 1 2 use crate::state::AppState; 2 3 use crate::util::{discord_app_id, discord_bot_username, telegram_bot_username}; 3 4 use axum::{Json, extract::State, http::StatusCode, response::IntoResponse}; ··· 55 56 "did": format!("did:web:{}", pds_hostname), 56 57 "links": links, 57 58 "contact": contact, 58 - "version": env!("CARGO_PKG_VERSION"), 59 + "version": BUILD_VERSION, 59 60 "availableCommsChannels": get_available_comms_channels(), 60 61 "selfHostedDidWebEnabled": is_self_hosted_did_web_enabled() 61 62 }); ··· 72 73 } 73 74 pub async fn health(State(state): State<AppState>) -> impl IntoResponse { 74 75 match state.infra_repo.health_check().await { 75 - Ok(true) => (StatusCode::OK, "OK"), 76 - _ => (StatusCode::SERVICE_UNAVAILABLE, "Service Unavailable"), 76 + Ok(true) => ( 77 + StatusCode::OK, 78 + Json(json!({ 79 + "version": format!("tranquil {}", BUILD_VERSION) 80 + })), 81 + ), 82 + _ => ( 83 + StatusCode::SERVICE_UNAVAILABLE, 84 + Json(json!({ 85 + "error": "Service Unavailable" 86 + })), 87 + ), 77 88 } 78 89 }
+10
crates/tranquil-pds/src/lib.rs
··· 43 43 pub use tranquil_db_traits::AccountStatus; 44 44 pub use types::{AccountState, AtIdentifier, AtUri, Did, Handle, Nsid, Rkey}; 45 45 46 + #[cfg(debug_assertions)] 47 + pub const BUILD_VERSION: &str = concat!( 48 + env!("CARGO_PKG_VERSION"), 49 + " (built ", 50 + env!("BUILD_TIMESTAMP"), 51 + ")" 52 + ); 53 + #[cfg(not(debug_assertions))] 54 + pub const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION"); 55 + 46 56 pub fn app(state: AppState) -> Router { 47 57 let xrpc_router = Router::new() 48 58 .route("/_health", get(api::server::health))
+1 -10
crates/tranquil-pds/src/main.rs
··· 5 5 use std::sync::Arc; 6 6 use tokio_util::sync::CancellationToken; 7 7 use tracing::{error, info, warn}; 8 + use tranquil_pds::BUILD_VERSION; 8 9 use tranquil_pds::comms::{CommsService, DiscordSender, EmailSender, SignalSender, TelegramSender}; 9 - 10 - #[cfg(debug_assertions)] 11 - const BUILD_VERSION: &str = concat!( 12 - env!("CARGO_PKG_VERSION"), 13 - " (built ", 14 - env!("BUILD_TIMESTAMP"), 15 - ")" 16 - ); 17 - #[cfg(not(debug_assertions))] 18 - const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION"); 19 10 20 11 use tranquil_pds::crawlers::{Crawlers, start_crawlers_service}; 21 12 use tranquil_pds::scheduled::{