From e72fa092fbd2a67ecfd00ad724b1d4f91609b17b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 16 Dec 2024 02:32:19 +0100 Subject: [PATCH] `apub_inbox`: Add `/.healthcheck` route --- acrate_apub_inbox/src/main.rs | 1 + acrate_apub_inbox/src/route.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/acrate_apub_inbox/src/main.rs b/acrate_apub_inbox/src/main.rs index 26dd56f..9a791f5 100644 --- a/acrate_apub_inbox/src/main.rs +++ b/acrate_apub_inbox/src/main.rs @@ -16,6 +16,7 @@ async fn main() -> anyhow::Result { log::trace!("Creating Axum router..."); let app = axum::Router::new() + .route("/.healthcheck", axum::routing::get(route::healthcheck_handler)) .layer(Extension(Arc::new(mj))); log::trace!("Axum router created successfully!"); diff --git a/acrate_apub_inbox/src/route.rs b/acrate_apub_inbox/src/route.rs index e69de29..97482d8 100644 --- a/acrate_apub_inbox/src/route.rs +++ b/acrate_apub_inbox/src/route.rs @@ -0,0 +1,14 @@ +use axum::http::StatusCode; +use acrate_database::connect::connect_async; + +pub async fn healthcheck_handler() -> Result { + log::debug!("Handling an healthcheck request!"); + + log::trace!("Making sure the database is up..."); + let _conn = connect_async() + .await + .map_err(|_| StatusCode::BAD_GATEWAY)?; + + log::trace!("Healthcheck successful! Everything's fine!"); + Ok(StatusCode::NO_CONTENT) +}