Skip to content

Commit

Permalink
feat(backend): add health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lindtvedtsebastian committed Aug 1, 2024
1 parent 5d7638d commit ce6fd02
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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};
Expand Down Expand Up @@ -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);

Expand All @@ -71,6 +71,13 @@ async fn main() {
.unwrap()
}

async fn check_health(State(mut state): State<AppState>) -> StatusCode {
if state.replicas.check_connection() {
return StatusCode::OK;
}
StatusCode::INTERNAL_SERVER_ERROR
}

async fn active_boards(
AuthBearer(token): AuthBearer,
State(mut state): State<AppState>,
Expand Down

0 comments on commit ce6fd02

Please sign in to comment.