Files
llm-intelligence/healthcheck.sh
2026-05-29 18:48:48 +08:00

36 lines
907 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
source scripts/report_utils.sh
if [[ -f ".env.local" ]]; then
# shellcheck disable=SC1091
source ".env.local"
fi
if [[ -f ".env" ]]; then
# shellcheck disable=SC1091
source ".env"
fi
DB_URL="${DATABASE_URL:-host=/var/run/postgresql dbname=llm_intelligence user=long sslmode=disable}"
TODAY="$(report_date_value)"
REPORT_PATH="$(report_markdown_path "$TODAY")"
psql "$DB_URL" -Atqc "select 1;" >/dev/null
if [[ -f "$REPORT_PATH" ]]; then
echo "healthcheck: ok (db=up report=$REPORT_PATH)"
exit 0
fi
LATEST_REPORT="$(find "$(report_output_dir)" -maxdepth 1 -type f -name 'daily_report_*.md' | sort | tail -n 1)"
if [[ -n "$LATEST_REPORT" ]]; then
echo "healthcheck: ok (db=up latest_report=$LATEST_REPORT)"
exit 0
fi
echo "healthcheck: degraded (db=up report=missing)"
exit 1