Skip to content

Commit

Permalink
Implement better liveness probe (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
smrtrfszm authored Nov 3, 2024
1 parent 22e24f2 commit e70d6e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
name: cargo-deny check ${{ matrix.checks }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
checks:
- advisories
Expand Down
17 changes: 16 additions & 1 deletion src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ mod team;

use crate::{middlewares::PermissionsLayer, state::StateTrait};
use axum::{
extract::State,
handler::Handler,
http::StatusCode,
routing::{get, post},
Router,
};
use sea_orm::ConnectionTrait;

pub fn routes<S: StateTrait>(state: S) -> Router<S> {
Router::new()
Expand All @@ -26,6 +29,18 @@ pub fn routes<S: StateTrait>(state: S) -> Router<S> {
.layer(PermissionsLayer::new(state, &["mathcompetition.admin"])),
),
)
.route("/liveness", get(|| async {}))
.route("/liveness", get(liveness::<S>))
.route("/readiness", get(|| async {}))
}

async fn liveness<S: StateTrait>(State(state): State<S>) -> StatusCode {
if state.db().execute_unprepared("select 1").await.is_err() {
return StatusCode::INTERNAL_SERVER_ERROR;
}

if state.nats().connection_state() != async_nats::connection::State::Connected {
return StatusCode::INTERNAL_SERVER_ERROR;
}

StatusCode::OK
}

0 comments on commit e70d6e5

Please sign in to comment.