feat(performance-point): switch performance calculator to performance-server (#80)

* feat(config): make `performance_server` as default calculator

* deploy(docker): use osu-performance-server

* docs(readme): add ruleset download instructions

* chore(dev): update development environment

* feat(dev): update development environment setup and service startup order

* fix(deps): move `rosu-pp-py` to `project.optional-dependencies`

* feat(beatmap): handle deleted beatmaps

* feat(performance-server): add a long timeout for calculation

* feat(recalculate): enhance CLI arguments for performance, leaderboard, and rating recalculations with CSV output support

* fix(recalculate): resolve reviews

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix(beatmapsync): resolve too long line

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
MingxuanGame
2025-11-09 01:59:09 +08:00
committed by GitHub
parent 293e57aea3
commit 0be3e903d4
20 changed files with 942 additions and 264 deletions

View File

@@ -107,6 +107,6 @@
80,
8080
],
"postCreateCommand": "uv sync --dev && uv run alembic upgrade head && uv run pre-commit install && cd spectator-server && dotnet restore",
"postCreateCommand": "uv sync --dev --all-extras && uv run alembic upgrade head && uv run pre-commit install && cd spectator-server && dotnet restore && cd ../performance-server && dotnet restore",
"remoteUser": "vscode"
}

View File

@@ -22,6 +22,7 @@ services:
REDIS_URL: redis://redis:6379/0
OSU_CLIENT_ID: "5"
OSU_CLIENT_SECRET: "FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk"
CALCULATOR_CONFIG: '{"server_url":"http://localhost:8090"}'
# Spectator Server 环境变量
SAVE_REPLAYS: "0"
@@ -34,11 +35,12 @@ services:
SHARED_INTEROP_SECRET: "dev-interop-secret"
SENTRY_DSN: "https://5840d8cb8d2b4d238369443bedef1d74@glitchtip.g0v0.top/4"
USE_LEGACY_RSA_AUTH: "0"
# .NET 环境变量
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
DOTNET_NOLOGO: "1"
RULESETS_PATH: "/workspaces/osu_lazer_api/rulesets"
mysql:
image: mysql:8.0
restart: unless-stopped

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# 开发环境启动脚本
# 同时启动 FastAPI Spectator Server
# 按依赖顺序启动Performance Server → FastAPI Spectator Server
set -e
@@ -16,27 +16,92 @@ fi
echo "🚀 启动开发环境..."
# 启动 FastAPI 服务器
# 清理函数
cleanup() {
echo "🛑 正在停止服务..."
[ ! -z "$SPECTATOR_PID" ] && kill $SPECTATOR_PID 2>/dev/null || true
[ ! -z "$FASTAPI_PID" ] && kill $FASTAPI_PID 2>/dev/null || true
[ ! -z "$PERFORMANCE_PID" ] && kill $PERFORMANCE_PID 2>/dev/null || true
exit ${1:-0}
}
# 捕获中断信号和错误
trap 'cleanup 1' INT TERM ERR
# 健康检查函数
wait_for_service() {
local url=$1
local service_name=$2
local pre_sleep=$3
local max_attempts=30
local attempt=0
echo "等待 $service_name 启动..."
if [ ! -z "$pre_sleep" ]; then
sleep $pre_sleep
fi
while [ $attempt -lt $max_attempts ]; do
# 使用 curl 检查,添加 10 秒超时,区分连接失败和 HTTP 错误
http_code=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 5 "$url" 2>/dev/null || echo "000")
if [ "$http_code" = "200" ] || [ "$http_code" = "404" ]; then
echo "$service_name 已就绪 (HTTP $http_code)"
return 0
elif [ "$http_code" = "000" ]; then
# 连接被拒绝或超时,服务还在启动中
echo "$service_name 正在启动... (尝试 $((attempt + 1))/$max_attempts)"
else
# 其他 HTTP 状态码
echo " ⚠️ $service_name 返回 HTTP $http_code (尝试 $((attempt + 1))/$max_attempts)"
fi
attempt=$((attempt + 1))
sleep 2
done
echo "$service_name 启动超时"
return 1
}
# 1. 启动 Performance Server (最底层依赖)
echo "启动 Performance Server..."
cd /workspaces/osu_lazer_api/performance-server
dotnet run --project PerformanceServer --urls "http://0.0.0.0:8090" &
PERFORMANCE_PID=$!
# 等待 Performance Server 就绪
if ! wait_for_service "http://localhost:8090" "Performance Server"; then
echo "Performance Server 启动失败,停止启动流程"
cleanup 1
fi
# 2. 启动 FastAPI 服务器 (依赖 Performance Server)
echo "启动 FastAPI 服务器..."
cd /workspaces/osu_lazer_api
uv run uvicorn main:app --host 0.0.0.0 --port 8000 --reload &
FASTAPI_PID=$!
# 启动 Spectator Server
# 等待 FastAPI 就绪
if ! wait_for_service "http://localhost:8000/health" "FastAPI"; then
echo "FastAPI 启动失败,停止启动流程"
cleanup 1
fi
# 3. 启动 Spectator Server (依赖 FastAPI)
echo "启动 Spectator Server..."
cd /workspaces/osu_lazer_api/spectator-server
dotnet run --project osu.Server.Spectator --urls "http://0.0.0.0:8086" &
SPECTATOR_PID=$!
echo "✅ 服务已启动:"
echo ""
echo "✅ 所有服务已启动:"
echo " - FastAPI: http://localhost:8000"
echo " - Spectator Server: http://localhost:8086"
echo " - Performance Server: http://localhost:8090"
echo " - Nginx (统一入口): http://localhost:8080"
echo ""
echo "按 Ctrl+C 停止所有服务"
# 等待用户中断
trap 'echo "🛑 正在停止服务..."; kill $FASTAPI_PID $SPECTATOR_PID; exit 0' INT
# 保持脚本运行
wait