feat(report): ship daily report v1 experience
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
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
|
||||
@@ -23,16 +24,56 @@ if [[ -z "${OPENROUTER_API_KEY:-}" ]]; then
|
||||
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"
|
||||
|
||||
go run "./scripts/fetch_openrouter.go" \
|
||||
if ! go run "./scripts/fetch_openrouter.go" \
|
||||
-api-key "$OPENROUTER_API_KEY" \
|
||||
-db "$DATABASE_URL" \
|
||||
-out "$ROOT_DIR/models.json"
|
||||
-out "$ROOT_DIR/models.json"; then
|
||||
record_failure "真实采集失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
go run "./scripts/generate_daily_report.go" \
|
||||
-json "$ROOT_DIR/models.json" \
|
||||
-out "$ROOT_DIR/reports/daily"
|
||||
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 'models', count(*) from models union all select 'model_prices', count(*) from model_prices union all select 'report_runs', count(*) from report_runs order by 1;"
|
||||
"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;"
|
||||
|
||||
Reference in New Issue
Block a user