Files
llm-intelligence/healthcheck.sh
phamnazage-jpg 98b9203302
Some checks failed
CI / go-test (push) Has been cancelled
CI / scripts-regression (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / docker-build (push) Has been cancelled
fix: preserve local env overrides in shell pipelines
2026-05-30 16:38:38 +08:00

29 lines
1010 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
while IFS= read -r kv; do export "$kv"; done < <("$ROOT_DIR/scripts/load_project_env.sh" ".env.local")
while IFS= read -r kv; do key="${kv%%=*}"; [[ -n "$key" && -n "${!key:-}" ]] && continue; export "$kv"; done < <("$ROOT_DIR/scripts/load_project_env.sh" ".env")
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