diff --git a/backend/src/main.rs b/backend/src/main.rs index 4a9ff4107..da325ef6e 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -3,8 +3,7 @@ use std::time::Duration; use axum::{ body::Body, extract::{Path, State}, - http::{HeaderValue, Method, StatusCode}, - response::Response, + http::{HeaderValue, Method, Response, StatusCode}, routing::{get, post}, Json, Router, }; @@ -13,7 +12,7 @@ use axum_auth::AuthBearer; use serde_json::{from_str, Value}; use tokio::{net::TcpListener, time}; -use redis::AsyncCommands; +use redis::{AsyncCommands, ConnectionLike}; use tokio_stream::StreamExt; use tokio_util::{sync::CancellationToken, task::TaskTracker}; @@ -62,6 +61,7 @@ async fn main() { .route("/subscribe/:bid", get(subscribe)) .route("/refresh/:bid", post(trigger)) .route("/update", post(update)) + .route("/health", get(check_health)) .with_state(redis_clients) .layer(cors); @@ -71,6 +71,13 @@ async fn main() { .unwrap() } +async fn check_health(State(mut state): State) -> StatusCode { + if state.replicas.check_connection() { + return StatusCode::OK; + } + StatusCode::INTERNAL_SERVER_ERROR +} + async fn active_boards( AuthBearer(token): AuthBearer, State(mut state): State,