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 cc94449 commit c163934
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 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
2 changes: 1 addition & 1 deletion editoast/src/views/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async fn cache_and_get_mvt_tile(

let conn = &mut db_pool.get().await?;
let records =
GeoJsonAndData::get_records(conn, &layer, view, infra, &GeoPoint::new(z, x, y)).await?;
GeoJsonAndData::get_records(conn, layer, view, infra, &GeoPoint::new(z, x, y)).await?;

let mvt_bytes: Vec<u8> = create_and_fill_mvt_tile(layer_slug, records)
.to_bytes()
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 c163934

Please sign in to comment.