Files
llm-intelligence/healthcheck.sh
phamnazage-jpg 77e6610fd2
Some checks failed
CI / test (push) Has been cancelled
chore: prepare repository for publishing
2026-05-13 14:42:45 +08:00

35 lines
870 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
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="$(date +%Y-%m-%d)"
REPORT_PATH="reports/daily/daily_report_${TODAY}.md"
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 reports/daily -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