Skip to content

Commit

Permalink
editoast: add healthcheck command
Browse files Browse the repository at this point in the history
Signed-off-by: ElysaSrc <[email protected]>
  • Loading branch information
ElysaSrc committed Oct 11, 2024
1 parent 5c58af7 commit 3bf1a4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions editoast/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub enum Commands {
STDCMSearchEnv(StdcmSearchEnvCommands),
#[command(subcommand, about, long_about = "Roles related commands")]
Roles(RolesCommand),
#[command(about, long_about = "Healthcheck")]
Healthcheck,
}

#[derive(Subcommand, Debug)]
Expand Down
14 changes: 14 additions & 0 deletions editoast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use tower_http::cors::{Any, CorsLayer};
use tower_http::limit::RequestBodyLimitLayer;
use tower_http::normalize_path::NormalizePathLayer;
use tower_http::trace::TraceLayer;
use views::check_health;
use views::train_schedule::{TrainScheduleForm, TrainScheduleResult};

use colored::*;
Expand Down Expand Up @@ -266,9 +267,22 @@ async fn run() -> Result<(), Box<dyn Error + Send + Sync>> {
.map_err(Into::into)
}
},
Commands::Healthcheck => healthcheck_cmd(db_pool.into(), redis_config).await,
}
}

async fn healthcheck_cmd(
db_pool: Arc<DbConnectionPoolV2>,
redis_config: RedisConfig,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let redis = RedisClient::new(redis_config).unwrap();
check_health(db_pool, redis.into())
.await
.map_err(|e| CliError::new(1, format!("❌ healthcheck failed: {0}", e)))?;
println!("✅ Healthcheck passed");
Ok(())
}

async fn trains_export(
args: ExportTimetableArgs,
db_pool: Arc<DbConnectionPoolV2>,
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async fn health(
Ok("ok")
}

async fn check_health(
pub async fn check_health(
db_pool: Arc<DbConnectionPoolV2>,
redis_client: Arc<RedisClient>,
) -> Result<()> {
Expand Down

0 comments on commit 3bf1a4b

Please sign in to comment.