feat: conductor health check

This commit is contained in:
Aravinth Manivannan 2022-10-05 17:00:45 +05:30
parent 0998b2a2de
commit a73111b36f
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88

View file

@ -18,6 +18,8 @@ use actix_web::{web, HttpResponse, Responder};
use derive_builder::Builder; use derive_builder::Builder;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use libconductor::Conductor;
use crate::AppCtx; use crate::AppCtx;
use crate::{GIT_COMMIT_HASH, VERSION}; use crate::{GIT_COMMIT_HASH, VERSION};
@ -55,25 +57,25 @@ async fn build_details(ctx: AppCtx) -> impl Responder {
HttpResponse::Ok().json(build) HttpResponse::Ok().json(build)
} }
//#[derive(Clone, Debug, Deserialize, Builder, Serialize)] #[derive(Clone, Debug, Deserialize, Builder, Serialize)]
///// Health check return datatype /// Health check return datatype
//pub struct Health { pub struct Health {
// db: bool, conductor: bool,
//} }
//
///// checks all components of the system /// checks all components of the system
//#[actix_web_codegen_const_routes::get(path = "crate::API_V1_ROUTES.meta.health")] #[actix_web_codegen_const_routes::get(path = "crate::API_V1_ROUTES.meta.health")]
//async fn health(ctx: crate::AppCtx) -> impl Responder { async fn health(ctx: crate::AppCtx) -> impl Responder {
// let mut resp_builder = HealthBuilder::default(); let mut resp_builder = HealthBuilder::default();
//
// resp_builder.db(ctx.db.ping().await); resp_builder.conductor(ctx.conductor.health().await);
//
// HttpResponse::Ok().json(resp_builder.build().unwrap()) HttpResponse::Ok().json(resp_builder.build().unwrap())
//} }
//
pub fn services(cfg: &mut web::ServiceConfig) { pub fn services(cfg: &mut web::ServiceConfig) {
cfg.service(build_details); cfg.service(build_details);
// cfg.service(health); cfg.service(health);
} }
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
@ -98,23 +100,24 @@ pub mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
} }
// #[actix_rt::test] #[actix_rt::test]
// async fn health_works() { async fn health_works() {
// use actix_web::test; use actix_web::test;
//
// let settings = Settings::new().unwrap(); let settings = Settings::new().unwrap();
// let ctx = AppCtx::new(crate::ctx::Ctx::new(&settings).await); let ctx = AppCtx::new(crate::ctx::Ctx::new(&settings).await);
// let app = test::init_service(App::new().app_data(ctx.clone()).configure(services)).await; let app = test::init_service(App::new().app_data(ctx.clone()).configure(services)).await;
//
// let resp = test::call_service( let resp = test::call_service(
// &app, &app,
// test::TestRequest::get() test::TestRequest::get()
// .uri(API_V1_ROUTES.meta.health) .uri(API_V1_ROUTES.meta.health)
// .to_request(), .to_request(),
// ) )
// .await; .await;
// assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
//
// let health_resp: super::Health = test::read_body_json(resp).await; let health_resp: super::Health = test::read_body_json(resp).await;
// } assert!(health_resp.conductor);
}
} }