Download web_development/backend/app/api/platform_routes.py from lucky-loster/quant_test: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/lucky-loster/quant_test/resolve/main/web_development/backend/app/api/platform_routes.py
- Command line
-
hf download hf://lucky-loster/quant_test/web_development/backend/app/api/platform_routes.py
-
curl -L -o platform_routes.py https://huggingface.co/lucky-loster/quant_test/resolve/main/web_development/backend/app/api/platform_routes.py
2.03 kB
| """Platform service control API — online start/stop by feature module.""" | |
| from fastapi import APIRouter, HTTPException | |
| from app.services.platform_manager import platform_manager | |
| router = APIRouter(prefix="/platform", tags=["platform"]) | |
| async def list_platform_services(): | |
| services = [s.to_dict() for s in platform_manager.list_services()] | |
| return {"services": services} | |
| async def get_platform_service(service_id: str): | |
| try: | |
| return platform_manager.get_status(service_id).to_dict() | |
| except KeyError: | |
| raise HTTPException(status_code=404, detail=f"Unknown service: {service_id}") | |
| async def start_platform_service(service_id: str): | |
| try: | |
| service = await platform_manager.start(service_id) | |
| return { | |
| "message": f"{service.name} 已启动", | |
| "service": service.to_dict(), | |
| "services": [s.to_dict() for s in platform_manager.list_services()], | |
| } | |
| except KeyError: | |
| raise HTTPException(status_code=404, detail=f"Unknown service: {service_id}") | |
| except Exception as exc: | |
| raise HTTPException(status_code=500, detail=str(exc)) | |
| async def stop_platform_service(service_id: str): | |
| try: | |
| service = await platform_manager.stop(service_id) | |
| return { | |
| "message": f"{service.name} 已停止", | |
| "service": service.to_dict(), | |
| "services": [s.to_dict() for s in platform_manager.list_services()], | |
| } | |
| except KeyError: | |
| raise HTTPException(status_code=404, detail=f"Unknown service: {service_id}") | |
| except Exception as exc: | |
| raise HTTPException(status_code=500, detail=str(exc)) | |
| async def start_all_services(): | |
| services = [s.to_dict() for s in await platform_manager.start_all()] | |
| return {"message": "已尝试启动全部模块", "services": services} | |