Skip to content

Commit

Permalink
editoast: app health view refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadjetz committed Jul 4, 2024
1 parent bd5d5e7 commit ebdfe01
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
13 changes: 13 additions & 0 deletions editoast/editoast_models/src/app_health.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use diesel::sql_query;
use diesel_async::RunQueryDsl;

use crate::DbConnection;
use crate::EditoastModelsError;

pub struct AppHealth;

impl AppHealth {
pub async fn run_simple_request(conn: &mut DbConnection) -> Result<usize, EditoastModelsError> {
Ok(sql_query("SELECT 1").execute(conn).await?)
}
}
2 changes: 2 additions & 0 deletions editoast/editoast_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use diesel_async::{pooled_connection::deadpool::Pool, AsyncPgConnection};
mod db_connection_pool;
mod error;

pub mod app_health;

pub use db_connection_pool::create_connection_pool;
pub use db_connection_pool::DbConnectionPoolV2;
pub use error::EditoastModelsError;
Expand Down
9 changes: 3 additions & 6 deletions editoast/src/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub use openapi::OpenApiRoot;
use actix_web::get;
use actix_web::web::Data;
use actix_web::web::Json;
use diesel::sql_query;
use editoast_models::app_health::AppHealth;
use editoast_models::DbConnectionPoolV2;
use redis::cmd;
use serde_derive::Deserialize;
use serde_derive::Serialize;
Expand All @@ -49,7 +50,6 @@ use crate::infra_cache::operation;
use crate::models;
use crate::modelsv2;
use crate::RedisClient;
use editoast_models::DbConnectionPoolV2;

crate::routes! {
(health, version, core_version),
Expand Down Expand Up @@ -105,10 +105,7 @@ async fn health(
db_pool: Data<DbConnectionPoolV2>,
redis_client: Data<RedisClient>,
) -> Result<&'static str> {
use diesel_async::RunQueryDsl;
sql_query("SELECT 1")
.execute(db_pool.get().await?.deref_mut())
.await?;
AppHealth::run_simple_request(db_pool.get().await?.deref_mut()).await?;

let mut conn = redis_client.get_connection().await?;
cmd("PING").query_async::<_, ()>(&mut conn).await.unwrap();
Expand Down

0 comments on commit ebdfe01

Please sign in to comment.