liumaolin
commited on
Commit
·
e7ebdb0
1
Parent(s):
94c7b78
Remove `SystemConfig` and `SystemStartRequest` models and clean up related API routes and background tasks for simplified system startup and management.
Browse files
src/VoiceDialogue/api/routes/system_routes.py
CHANGED
|
@@ -6,8 +6,7 @@ from fastapi import APIRouter, HTTPException, BackgroundTasks, Request
|
|
| 6 |
|
| 7 |
from ..core.service_factories import get_audio_capture_service_definition
|
| 8 |
from ..schemas.system_schemas import (
|
| 9 |
-
SystemStatusResponse,
|
| 10 |
-
SystemStartRequest, SystemResponse
|
| 11 |
)
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
|
@@ -17,7 +16,6 @@ router = APIRouter()
|
|
| 17 |
_system_status = {
|
| 18 |
"status": "stopped",
|
| 19 |
"start_time": None,
|
| 20 |
-
"config": None,
|
| 21 |
"active_sessions": 0
|
| 22 |
}
|
| 23 |
|
|
@@ -64,7 +62,6 @@ async def get_system_status(request: Request):
|
|
| 64 |
|
| 65 |
@router.post("/start", response_model=SystemResponse, summary="启动系统")
|
| 66 |
async def start_system(
|
| 67 |
-
request: SystemStartRequest,
|
| 68 |
fastapi_request: Request,
|
| 69 |
background_tasks: BackgroundTasks
|
| 70 |
):
|
|
@@ -80,12 +77,10 @@ async def start_system(
|
|
| 80 |
|
| 81 |
# 更新状态
|
| 82 |
_system_status["status"] = "starting"
|
| 83 |
-
_system_status["config"] = request.config
|
| 84 |
|
| 85 |
# 在后台启动系统
|
| 86 |
background_tasks.add_task(
|
| 87 |
_start_system_background,
|
| 88 |
-
request.config,
|
| 89 |
fastapi_request
|
| 90 |
)
|
| 91 |
|
|
@@ -141,7 +136,6 @@ async def stop_system(request: Request):
|
|
| 141 |
|
| 142 |
_system_status["status"] = "stopped"
|
| 143 |
_system_status["start_time"] = None
|
| 144 |
-
_system_status["config"] = None
|
| 145 |
_system_status["active_sessions"] = 0
|
| 146 |
|
| 147 |
return SystemResponse(
|
|
@@ -156,7 +150,6 @@ async def stop_system(request: Request):
|
|
| 156 |
|
| 157 |
@router.post("/restart", response_model=SystemResponse, summary="重启系统")
|
| 158 |
async def restart_system(
|
| 159 |
-
request: SystemStartRequest,
|
| 160 |
fastapi_request: Request,
|
| 161 |
background_tasks: BackgroundTasks
|
| 162 |
):
|
|
@@ -169,14 +162,14 @@ async def restart_system(
|
|
| 169 |
await stop_system(fastapi_request)
|
| 170 |
|
| 171 |
# 再启动
|
| 172 |
-
return await start_system(
|
| 173 |
|
| 174 |
except Exception as e:
|
| 175 |
logger.error(f"系统重启失败: {e}", exc_info=True)
|
| 176 |
raise HTTPException(status_code=500, detail=f"系统重启失败: {str(e)}")
|
| 177 |
|
| 178 |
|
| 179 |
-
async def _start_system_background(
|
| 180 |
"""
|
| 181 |
后台启动系统的实际逻辑 - 创建并启动audio_capture服务
|
| 182 |
"""
|
|
|
|
| 6 |
|
| 7 |
from ..core.service_factories import get_audio_capture_service_definition
|
| 8 |
from ..schemas.system_schemas import (
|
| 9 |
+
SystemStatusResponse, SystemResponse
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
|
|
|
| 16 |
_system_status = {
|
| 17 |
"status": "stopped",
|
| 18 |
"start_time": None,
|
|
|
|
| 19 |
"active_sessions": 0
|
| 20 |
}
|
| 21 |
|
|
|
|
| 62 |
|
| 63 |
@router.post("/start", response_model=SystemResponse, summary="启动系统")
|
| 64 |
async def start_system(
|
|
|
|
| 65 |
fastapi_request: Request,
|
| 66 |
background_tasks: BackgroundTasks
|
| 67 |
):
|
|
|
|
| 77 |
|
| 78 |
# 更新状态
|
| 79 |
_system_status["status"] = "starting"
|
|
|
|
| 80 |
|
| 81 |
# 在后台启动系统
|
| 82 |
background_tasks.add_task(
|
| 83 |
_start_system_background,
|
|
|
|
| 84 |
fastapi_request
|
| 85 |
)
|
| 86 |
|
|
|
|
| 136 |
|
| 137 |
_system_status["status"] = "stopped"
|
| 138 |
_system_status["start_time"] = None
|
|
|
|
| 139 |
_system_status["active_sessions"] = 0
|
| 140 |
|
| 141 |
return SystemResponse(
|
|
|
|
| 150 |
|
| 151 |
@router.post("/restart", response_model=SystemResponse, summary="重启系统")
|
| 152 |
async def restart_system(
|
|
|
|
| 153 |
fastapi_request: Request,
|
| 154 |
background_tasks: BackgroundTasks
|
| 155 |
):
|
|
|
|
| 162 |
await stop_system(fastapi_request)
|
| 163 |
|
| 164 |
# 再启动
|
| 165 |
+
return await start_system( fastapi_request, background_tasks)
|
| 166 |
|
| 167 |
except Exception as e:
|
| 168 |
logger.error(f"系统重启失败: {e}", exc_info=True)
|
| 169 |
raise HTTPException(status_code=500, detail=f"系统重启失败: {str(e)}")
|
| 170 |
|
| 171 |
|
| 172 |
+
async def _start_system_background(request: Request):
|
| 173 |
"""
|
| 174 |
后台启动系统的实际逻辑 - 创建并启动audio_capture服务
|
| 175 |
"""
|
src/VoiceDialogue/api/schemas/system_schemas.py
CHANGED
|
@@ -15,18 +15,6 @@ class SystemStatusResponse(BaseModel):
|
|
| 15 |
services_details: Optional[Dict[str, Any]] = Field(None, description="服务详细状态信息")
|
| 16 |
|
| 17 |
|
| 18 |
-
class SystemConfig(BaseModel):
|
| 19 |
-
"""系统配置"""
|
| 20 |
-
language: Optional[str] = Field(default="zh", description="系统语言")
|
| 21 |
-
sample_rate: Optional[int] = Field(default=16000, description="音频采样率")
|
| 22 |
-
enable_logging: Optional[bool] = Field(default=True, description="是否启用日志")
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
class SystemStartRequest(BaseModel):
|
| 26 |
-
"""系统启动请求"""
|
| 27 |
-
config: SystemConfig = Field(..., description="系统配置")
|
| 28 |
-
|
| 29 |
-
|
| 30 |
class SystemResponse(BaseModel):
|
| 31 |
"""系统操作响应"""
|
| 32 |
success: bool = Field(..., description="操作是否成功")
|
|
|
|
| 15 |
services_details: Optional[Dict[str, Any]] = Field(None, description="服务详细状态信息")
|
| 16 |
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
class SystemResponse(BaseModel):
|
| 19 |
"""系统操作响应"""
|
| 20 |
success: bool = Field(..., description="操作是否成功")
|