fix: 避免连接测试阻塞事件循环

This commit is contained in:
2026-06-25 14:04:16 +08:00
parent c746080b3e
commit 1f9074eb41
3 changed files with 8 additions and 3 deletions
+2 -2
View File
@@ -137,7 +137,7 @@ async def update_cell_data_mysql_config(config: dict[str, Any] = Body(...)):
@router.post("/api/config/cell-data/remote/test")
async def test_cell_data_remote_connection(config: dict[str, Any] | None = Body(None)):
def test_cell_data_remote_connection(config: dict[str, Any] | None = Body(None)):
try:
remote_config = RemoteDataConfig.from_dict(config) if config else state.current_config().cell_data.remote_data
RemoteDataDownloader(remote_config).test_connection()
@@ -147,7 +147,7 @@ async def test_cell_data_remote_connection(config: dict[str, Any] | None = Body(
@router.post("/api/config/cell-data/mysql/test")
async def test_cell_data_mysql_connection(config: dict[str, Any] | None = Body(None)):
def test_cell_data_mysql_connection(config: dict[str, Any] | None = Body(None)):
mysql_config = MySQLConfig.from_dict(config, default_dbname="celldata") if config else state.current_config().cell_data.mysql
return _test_mysql_config(mysql_config)
+1 -1
View File
@@ -25,7 +25,7 @@ router = APIRouter(tags=["remote"])
@router.post("/api/remote/test")
async def test_remote_connection(config: dict[str, Any] | None = Body(None)):
def test_remote_connection(config: dict[str, Any] | None = Body(None)):
app_config = state.current_config()
try:
if app_config.source_type == "metrix":
+5
View File
@@ -841,3 +841,8 @@
- 新增 `app.utils.files.safe_relative_path()`,容量数据上传和 CellData 本地上传保存文件前统一过滤空片段、`.` 与 `..`,避免客户端文件名或 `webkitRelativePath` 中的路径穿越片段写出任务工作目录,同时保留合法的文件夹层级。
- 验证:`safe_relative_path` 典型路径断言通过;`python -m compileall -q app` 通过;`frontend` `npm run build` 通过;构建产物已清理。
## 2026-06-25:连接测试接口改为线程池执行
- `/api/remote/test`、`/api/config/cell-data/remote/test`、`/api/config/cell-data/mysql/test` 改为同步路由函数,保持响应结构不变,但让 FastAPI 在线程池中执行 FTP/SFTP、Metrix 平台 HTTP 与 MySQL 连接测试,避免慢连接或超时阻塞事件循环。
- 验证:`.venv\Scripts\python.exe -m compileall -q app` 通过;`frontend` `npm run build` 通过;构建产物已清理。