Skip to content

Commit

Permalink
Added Health Endpoint (#30)
Browse files Browse the repository at this point in the history
* feat: added minimal health endpoint
  • Loading branch information
torbrenner committed Jun 20, 2024
1 parent 2bf93fc commit af7aba8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
docker-compose.override.yml
target/
Cargo.lock

*.priv.pem
docker-compose.override.yml
18 changes: 18 additions & 0 deletions src/health.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use serde::Serialize;


#[derive(Serialize)]
pub struct HealthOutput {
pub summary: Verdict,
pub beam: BeamStatus
}

#[derive(Serialize)]
pub enum Verdict {
Healthy,
}

#[derive(Serialize)]
pub enum BeamStatus {
Ok,
}
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ use tracing::{info, warn, Level};
use tracing_subscriber::{util::SubscriberInitExt, EnvFilter};
use tokio::{io::AsyncWriteExt, sync::{mpsc, Mutex}};
use futures_util::{TryFutureExt, TryStreamExt};
use health::{BeamStatus, HealthOutput, Verdict};

mod banner;
mod beam;
mod catalogue;
mod config;
mod health;

static CONFIG: Lazy<Config> = Lazy::new(Config::parse);

Expand Down Expand Up @@ -67,6 +69,7 @@ async fn main() {
.allow_headers([header::CONTENT_TYPE]);

let mut app = Router::new()
.route("/health", get(handler_health))
.route("/beam", post(handle_create_beam_task))
.route("/beam/:task_id", get(handle_listen_to_beam_tasks));

Expand Down Expand Up @@ -98,6 +101,13 @@ struct LensQuery {
query: String,
}

async fn handler_health() -> Json<HealthOutput> {
Json(HealthOutput {
summary: Verdict::Healthy,
beam: BeamStatus::Ok
})
}

async fn handle_create_beam_task(
State(SharedState { result_log_sender_map, .. }): State<SharedState>,
headers: HeaderMap,
Expand Down

0 comments on commit af7aba8

Please sign in to comment.