Commit c3fbc3a4 by imwangxiaozhou

feat(服务脚本&编排服务): 添加停止服务脚本,优化启动脚本并修复编排逻辑

新增 stop-all.bat 批处理脚本用于一键停止所有平台服务。优化 start-all.bat 脚本,将中文提示替换为英文并调整窗口标题,移除冗余的Redis等待延时。重构后端编排服务代码,统一异步任务的模拟ID生成逻辑,移除重复赋值代码并添加详细注释。
1 parent 6baf4042
...@@ -262,10 +262,11 @@ async def orchestrate_async( ...@@ -262,10 +262,11 @@ async def orchestrate_async(
db.add(call_record) db.add(call_record)
await db.flush() await db.flush()
# 5. 创建异步任务记录 # 5. 创建异步任务记录(先使用 mock ID 保证唯一性,Celery 可用时再覆盖)
mock_task_id = f"mock-{uuid.uuid4().hex[:12]}"
async_task = AsyncTask( async_task = AsyncTask(
call_record_id=call_record.id, call_record_id=call_record.id,
celery_task_id="", celery_task_id=mock_task_id,
status="pending", status="pending",
progress=0, progress=0,
) )
...@@ -281,8 +282,6 @@ async def orchestrate_async( ...@@ -281,8 +282,6 @@ async def orchestrate_async(
# 保持 pending — Celery Worker 真正开始执行时再改为 processing # 保持 pending — Celery Worker 真正开始执行时再改为 processing
logger.info(f"异步任务已提交到 Celery: task_id={async_task.id}, celery_id={celery_task.id}") logger.info(f"异步任务已提交到 Celery: task_id={async_task.id}, celery_id={celery_task.id}")
else: else:
async_task.celery_task_id = f"mock-{uuid.uuid4().hex[:12]}"
# mock 模式下标记为 processing(因为没有 Worker 会消费)
async_task.status = "processing" async_task.status = "processing"
logger.warning(f"Celery 不可用,异步任务使用模拟模式: task_id={async_task.id}") logger.warning(f"Celery 不可用,异步任务使用模拟模式: task_id={async_task.id}")
...@@ -574,10 +573,11 @@ async def orchestrate_by_template( ...@@ -574,10 +573,11 @@ async def orchestrate_by_template(
} }
else: # mode == "async" else: # mode == "async"
# 创建异步任务记录 # 创建异步任务记录(先使用 mock ID 保证唯一性,Celery 可用时再覆盖)
mock_task_id = f"mock-{uuid.uuid4().hex[:12]}"
async_task = AsyncTask( async_task = AsyncTask(
call_record_id=call_record.id, call_record_id=call_record.id,
celery_task_id="", celery_task_id=mock_task_id,
status="pending", status="pending",
progress=0, progress=0,
) )
...@@ -592,7 +592,6 @@ async def orchestrate_by_template( ...@@ -592,7 +592,6 @@ async def orchestrate_by_template(
async_task.celery_task_id = celery_task.id async_task.celery_task_id = celery_task.id
# 保持 pending — Worker 开始执行时再改为 processing # 保持 pending — Worker 开始执行时再改为 processing
else: else:
async_task.celery_task_id = f"mock-{uuid.uuid4().hex[:12]}"
async_task.status = "processing" async_task.status = "processing"
await db.flush() await db.flush()
......
@echo off @echo off
chcp 65001 >nul chcp 65001 >nul
title LLM Call Platform - 一键启动 title LLM Call Platform - Start All Services
set ROOT=%~dp0 set ROOT=%~dp0
set BACKEND=%ROOT%backend set BACKEND=%ROOT%backend
set FRONTEND=%ROOT%frontend set FRONTEND=%ROOT%frontend
echo ======================================== echo ========================================
echo LLM Call Platform - 启动所有服务 echo LLM Call Platform - Starting Services
echo ======================================== echo ========================================
echo. echo.
:: 1. Redis :: 1. Redis
echo [1/4] 启动 Redis ... echo [1/4] Starting Redis ...
start "Redis" /MIN redis-server start "Redis" /MIN redis-server
:: 等待 Redis 就绪
timeout /t 2 /nobreak >nul timeout /t 2 /nobreak >nul
:: 2. Celery Worker :: 2. Celery Worker
echo [2/4] 启动 Celery Worker ... echo [2/4] Starting Celery Worker ...
cd /d "%BACKEND%" cd /d "%BACKEND%"
start "Celery" /MIN cmd /c "celery -A app.celery_app worker -l info -P solo" start "Celery" /MIN cmd /c "celery -A app.celery_app worker -l info -P solo"
:: 3. 后端 FastAPI :: 3. Backend FastAPI
echo [3/4] 启动后端 (uvicorn :8011) ... echo [3/4] Starting Backend (uvicorn :8011) ...
cd /d "%BACKEND%" cd /d "%BACKEND%"
start "Backend" cmd /c "python -m uvicorn app.main:app --host 0.0.0.0 --port 8011" start "Backend" cmd /c "python -m uvicorn app.main:app --host 0.0.0.0 --port 8011"
:: 4. 前端 Vite :: 4. Frontend Vite
echo [4/4] 启动前端 (vite :5273) ... echo [4/4] Starting Frontend (vite :5273) ...
cd /d "%FRONTEND%" cd /d "%FRONTEND%"
start "Frontend" cmd /c "npm run dev" start "Frontend" cmd /c "npm run dev"
echo. echo.
echo ======================================== echo ========================================
echo 所有服务已启动! echo All services started!
echo. echo.
echo 后端 API: http://localhost:8011 echo Backend API: http://localhost:8011
echo 健康检查: http://localhost:8011/api/health echo Health Check: http://localhost:8011/api/health
echo 前端页面: http://localhost:5273 echo Frontend: http://localhost:5273
echo 接口文档: http://localhost:8011/docs echo API Docs: http://localhost:8011/docs
echo ======================================== echo ========================================
echo. echo.
echo 按任意键关闭此窗口(服务将继续在后台运行) echo Press any key to close this window.
pause >nul pause >nul
@echo off
chcp 65001 >nul
title LLM Call Platform - Stop All Services
echo ========================================
echo LLM Call Platform - Stopping Services
echo ========================================
echo.
:: 1. Frontend (Vite / Node)
echo [1/4] Stopping Frontend (Vite) ...
taskkill /f /fi "WINDOWTITLE eq Frontend" /t >nul 2>&1
:: 2. Backend (Uvicorn)
echo [2/4] Stopping Backend (Uvicorn) ...
taskkill /f /fi "WINDOWTITLE eq Backend" /t >nul 2>&1
:: 3. Celery Worker
echo [3/4] Stopping Celery Worker ...
taskkill /f /fi "WINDOWTITLE eq Celery" /t >nul 2>&1
:: 4. Redis
echo [4/4] Stopping Redis ...
taskkill /f /fi "WINDOWTITLE eq Redis" /t >nul 2>&1
:: 后备:清理残留进程
taskkill /f /im uvicorn.exe >nul 2>&1
taskkill /f /im node.exe >nul 2>&1
taskkill /f /im python.exe >nul 2>&1
taskkill /f /im redis-server.exe >nul 2>&1
echo.
echo ========================================
echo All services stopped!
echo ========================================
echo.
pause
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!