From 3003f4cf7829c967c708b616a6cb6f3bfa62fa9c Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Fri, 9 Dec 2022 07:57:37 -0500 Subject: [PATCH] minor healthcheck/docker fixes --- docker-compose.live.yaml | 4 ++-- services/api/src/health.rs | 36 +++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docker-compose.live.yaml b/docker-compose.live.yaml index 5cacd57..fa2d310 100644 --- a/docker-compose.live.yaml +++ b/docker-compose.live.yaml @@ -36,9 +36,9 @@ services: links: - tsdb - prune: + task_prune: image: ghcr.io/genudine/saerro/tasks:latest - command: prune + command: /app prune pull_policy: always restart: "no" environment: diff --git a/services/api/src/health.rs b/services/api/src/health.rs index 1c9ac2a..84eca16 100644 --- a/services/api/src/health.rs +++ b/services/api/src/health.rs @@ -71,25 +71,39 @@ impl Health { } } - /// Is the websocket connection to the Nanite Systems manifold up? - async fn websocket<'ctx>(&self, ctx: &Context<'ctx>) -> UpDown { + /// Is the websocket processing jobs? + async fn ingest<'ctx>(&self, ctx: &Context<'ctx>) -> UpDown { let pool = ctx.data::>().unwrap(); - match query("SELECT count(*) FROM analytics WHERE time > now() - interval '5 minutes'") - .fetch_one(pool) - .await - { - Ok(i) => { - let num: i64 = i.get(0); - if num == 0 { - UpDown::Down + let events_resp = + query("SELECT count(*) FROM analytics WHERE time > now() - interval '5 minutes'") + .fetch_one(pool) + .await; + + match events_resp { + Ok(row) => { + let events_row: i64 = row.get(0); + + if events_row == 0 { + return UpDown::Down; } else { - UpDown::Up + return UpDown::Up; } } Err(_) => UpDown::Down, } } + + /// Is the websocket actually turned on? + async fn ingest_reachable(&self) -> UpDown { + reqwest::get( + std::env::var("WEBSOCKET_HEALTHCHECK") + .unwrap_or("http://localhost:8999/health".to_string()), + ) + .await + .map(|_| UpDown::Up) + .unwrap_or(UpDown::Down) + } } #[derive(Default)]