Files
llm-intelligence/scripts/run_real_pipeline.sh
2026-05-13 20:13:02 +08:00

80 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. "$ROOT_DIR/scripts/report_utils.sh"
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
if [[ -z "${DATABASE_URL:-}" ]]; then
echo "DATABASE_URL 未设置" >&2
exit 1
fi
if [[ -z "${OPENROUTER_API_KEY:-}" ]]; then
echo "OPENROUTER_API_KEY 未设置,无法执行真实采集" >&2
exit 1
fi
REPORT_DATE="$(report_date_value)"
record_failure() {
local error_message output_path
error_message="$1"
output_path=""
if [[ -f "$(report_markdown_path "$REPORT_DATE")" ]]; then
output_path="$(report_markdown_path "$REPORT_DATE")"
fi
track_report_state "$DATABASE_URL" "$REPORT_DATE" "failed" "" "" "$output_path" "$error_message" >/dev/null 2>&1 || true
}
"$ROOT_DIR/scripts/apply_migration.sh"
if ! go run "./scripts/fetch_openrouter.go" \
-api-key "$OPENROUTER_API_KEY" \
-db "$DATABASE_URL" \
-out "$ROOT_DIR/models.json"; then
record_failure "真实采集失败"
exit 1
fi
if ! go run "./scripts/generate_daily_report.go"; then
record_failure "日报生成失败"
exit 1
fi
if [[ ! -f "$(report_archive_markdown_path "$REPORT_DATE")" || ! -f "$(report_archive_html_path "$REPORT_DATE")" ]]; then
record_failure "日报归档缺失"
exit 1
fi
if ! psql "$DATABASE_URL" -Atqc "select count(*) from daily_report where report_date = current_date and status = 'generated';" | awk '{ exit !($1 >= 1) }'; then
record_failure "daily_report 未写入 generated 记录"
exit 1
fi
if ! psql "$DATABASE_URL" -Atqc "select count(*) from report_runs where report_date = current_date and status = 'generated';" | awk '{ exit !($1 >= 1) }'; then
record_failure "report_runs 未写入 generated 记录"
exit 1
fi
psql "$DATABASE_URL" -Atqc \
"select 'daily_report', count(*) from daily_report where report_date = current_date
union all
select 'models', count(*) from models
union all
select 'region_pricing', count(*) from region_pricing
union all
select 'report_runs', count(*) from report_runs where report_date = current_date
order by 1;"