rustploy 0.1.5

Rustploy PaaS daemon — lightweight self-hosted deployment platform
//! `Command::DaemonStatus`: versão, uptime e contagem de serviços
//! rodando/total.

use crate::bootstrap::state::AppState;
use shared::Response as RpResponse;

pub async fn handle(state: AppState) -> RpResponse {
    let services = crate::store::services::get_running(&state.db)
        .await
        .unwrap_or_default();

    let total: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM service")
        .fetch_one(&*state.db)
        .await
        .unwrap_or(0);

    RpResponse::DaemonStatus(shared::DaemonStatus {
        version: env!("CARGO_PKG_VERSION").into(),
        uptime_secs: state.started_at.elapsed().as_secs(),
        services_running: services.len(),
        services_total: total as usize,
    })
}