From 0ac7a0447716cdaccc03b6782f2149da4c03b3da Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 12 Dec 2024 03:44:08 +0100 Subject: [PATCH] `rdserver`: Add `.healthcheck` route for monitoring purposes --- acrate_rdserver/src/main.rs | 1 + acrate_rdserver/src/route.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/acrate_rdserver/src/main.rs b/acrate_rdserver/src/main.rs index 3752cbf..ac14b4a 100644 --- a/acrate_rdserver/src/main.rs +++ b/acrate_rdserver/src/main.rs @@ -21,6 +21,7 @@ async fn main() -> anyhow::Result { log::trace!("Creating Axum router..."); let app = axum::Router::new() .route("/*path", axum::routing::get(route::webfinger_handler)) + .route("/.healthcheck", axum::routing::get(route::healthcheck_handler)) .layer(Extension(Arc::new(mj))); log::trace!("Axum router created successfully!"); diff --git a/acrate_rdserver/src/route.rs b/acrate_rdserver/src/route.rs index 61ba271..25bfbaa 100644 --- a/acrate_rdserver/src/route.rs +++ b/acrate_rdserver/src/route.rs @@ -13,6 +13,17 @@ use acrate_rd::jrd::ResourceDescriptorLinkJRD; use acrate_rd::xrd::{ResourceDescriptorLinkXRD, ResourceDescriptorPropertyXRD, ResourceDescriptorTitleXRD}; use crate::config; +pub async fn healthcheck_handler() -> Result { + log::info!("Handling an healthcheck request!"); + + log::trace!("Making sure the database is up..."); + let _conn = AsyncPgConnection::establish(config::ACRATE_WEBFINGER_DATABASE_URL()) + .await + .map_err(|_| StatusCode::BAD_GATEWAY)?; + + Ok(StatusCode::NO_CONTENT) +} + #[derive(Debug, Clone, Deserialize)] pub struct WebfingerQuery { pub resource: Option,