mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-19 07:29:24 +00:00
add ping endpoint and healthcheck command
This commit is contained in:
25
src/commands/health.rs
Normal file
25
src/commands/health.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use crate::config::HttpConfig;
|
||||
use clap::Parser;
|
||||
use http::Method;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct HealthArgs {}
|
||||
|
||||
/// Healthcheck for running rustical instance
|
||||
/// Currently just pings to see if it's reachable via HTTP
|
||||
pub async fn cmd_health(http_config: HttpConfig, _health_args: HealthArgs) -> anyhow::Result<()> {
|
||||
let client = reqwest::ClientBuilder::new().build().unwrap();
|
||||
|
||||
let endpoint = format!(
|
||||
"http://{host}:{port}/ping",
|
||||
host = http_config.host,
|
||||
port = http_config.port
|
||||
)
|
||||
.parse()
|
||||
.unwrap();
|
||||
let request = reqwest::Request::new(Method::GET, endpoint);
|
||||
|
||||
assert!(client.execute(request).await.unwrap().status().is_success());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -5,7 +5,8 @@ use crate::config::{
|
||||
use clap::Parser;
|
||||
use rustical_frontend::FrontendConfig;
|
||||
|
||||
mod membership;
|
||||
pub mod health;
|
||||
pub mod membership;
|
||||
pub mod principals;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
|
||||
Reference in New Issue
Block a user