use crate::routines;
use crate::utils::time::now_secs;
use serde::Serialize;
#[derive(Serialize, utoipa::ToSchema)]
pub struct DependencyHealth {
pub tmux: bool,
pub python3: bool,
}
#[derive(Serialize, utoipa::ToSchema)]
pub struct HealthResponse {
pub status: String,
pub uptime_secs: u64,
pub running: bool,
pub machine: String,
pub dependencies: DependencyHealth,
pub version: String,
pub git_sha: String,
pub build_date: String,
pub server_root: Option<String>,
pub server_exe_dir: Option<String>,
}
pub fn build(uptime_start: u64) -> HealthResponse {
let loc = crate::filesystem::FsLocation::current();
HealthResponse {
status: "ok".to_string(),
uptime_secs: now_secs().saturating_sub(uptime_start),
running: true,
machine: crate::machine::current_machine(),
dependencies: DependencyHealth {
tmux: routines::tmux_available(),
python3: routines::agent_command_available("python3"),
},
version: crate::build_info::VERSION.to_string(),
git_sha: crate::build_info::GIT_SHA.to_string(),
build_date: crate::build_info::BUILD_DATE.to_string(),
server_root: loc.server_root,
server_exe_dir: loc.server_exe_dir,
}
}
#[cfg(test)]
#[path = "logic_tests.rs"]
mod logic_tests;