fix:优化服务

This commit is contained in:
Daniel
2026-04-07 01:00:56 +08:00
parent 8d0b729f2f
commit e606b3dcd6
19 changed files with 899 additions and 7 deletions

View File

@@ -45,6 +45,21 @@ cd video_worker
.\scripts\install_windows_env.ps1
```
### Windows 终端PowerShell里调用 WSL 安装并启动
在仓库里进入 `video_worker` 后执行(无图形界面、仅 CLI
```powershell
cd video_worker
.\scripts\run_wsl_one_click.ps1
```
多个 WSL 发行版时指定名称(与 `wsl -l -v` 中一致):
```powershell
.\scripts\run_wsl_one_click.ps1 -Distro Ubuntu-22.04
```
## 5. 启动命令
### WSL / Linux
@@ -54,6 +69,20 @@ cd video_worker
bash scripts/run_server.sh
```
独立 WS 网关服务(远程推荐):
```bash
cd video_worker
bash scripts/run_ws_service.sh
```
Docker 部署HTTP -> WS 边缘下发):
```bash
cd video_worker
bash scripts/run_edge_dispatch_docker.sh
```
### Windows
```powershell
@@ -61,6 +90,13 @@ cd video_worker
.\scripts\run_server.ps1
```
独立 WS 网关服务:
```powershell
cd video_worker
.\scripts\run_ws_service.ps1
```
或:
```bat
@@ -119,11 +155,13 @@ video_worker/
│ │ ├─ base.py
│ │ ├─ ltx_backend.py
│ │ └─ hunyuan_backend.py
─ utils/
├─ files.py
├─ ffmpeg_utils.py
├─ image_utils.py
└─ logger.py
─ utils/
├─ files.py
├─ ffmpeg_utils.py
├─ image_utils.py
└─ logger.py
│ ├─ ws_service.py
│ └─ edge_dispatch_service.py
├─ models/
│ ├─ ltx/
│ └─ hunyuan/
@@ -135,10 +173,22 @@ video_worker/
│ ├─ install_wsl_env.sh
│ ├─ install_windows_env.ps1
│ ├─ run_server.sh
│ ├─ run_ws_service.sh
│ ├─ run_server.ps1
│ ├─ run_ws_service.ps1
│ ├─ run_server.bat
│ ├─ run_ws_service.bat
│ ├─ run_edge_dispatch_docker.sh
│ ├─ stop_edge_dispatch_docker.sh
│ ├─ migrate_db.py
─ smoke_test.py
─ smoke_test.py
│ ├─ ws_smoke_test.py
│ └─ edge_device_client.py
├─ docker/
│ └─ edge-dispatch/
│ └─ Dockerfile
├─ docker-compose.edge-dispatch.yml
├─ .dockerignore
├─ requirements.txt
├─ .env.example
└─ README.md
@@ -154,6 +204,16 @@ video_worker/
- 查询结果路径或错误
- `GET /health`
- 服务状态、CUDA、GPU 名称、模型加载状态
- `WS /ws/generate`
- 远程服务通过 WebSocket 触发任务并接收状态推送
- `POST /dispatch/generate`edge_dispatch_service
- 对外 HTTP 入口,触发 WS 下发给边缘设备
- `GET /dispatch/{dispatch_id}`edge_dispatch_service
- 查询调度任务状态和结果
- `GET /devices`edge_dispatch_service
- 查看在线边缘设备
- `WS /ws/edge/{device_id}`edge_dispatch_service
- 边缘设备接入通道
参数限制:
@@ -163,6 +223,122 @@ video_worker/
- `fps`: <= 24
- `quality_mode`: `preview``refine`
### WebSocket 协议
连接地址:
```text
ws://<host>:<port>/ws/generate
```
如果使用独立网关,默认是:
```text
ws://<host>:8010/ws/generate
```
客户端发送(触发任务):
```json
{
"action": "generate",
"payload": {
"prompt": "a lonely man walking in a rainy neon street, cinematic, handheld camera",
"negative_prompt": "blurry, deformed face, extra limbs, flicker",
"quality_mode": "preview",
"duration_sec": 1,
"width": 320,
"height": 240,
"fps": 8,
"steps": 8,
"seed": 123456
}
}
```
也支持只订阅已存在任务:
```json
{
"action": "watch",
"task_id": "your_task_id"
}
```
服务端事件:
- `accepted`: 已创建任务并入队
- `status`: 状态变化推送(`PENDING/RUNNING/SUCCEEDED/FAILED`
- `result`: 最终结果(成功路径或失败错误)
- `error`: 请求错误或内部错误
WS 烟雾测试:
```bash
cd video_worker
. .venv/bin/activate # Windows: .\.venv\Scripts\Activate.ps1
python scripts/ws_smoke_test.py
```
远程部署建议:
1. Worker 服务运行在 `8000` 端口(`scripts/run_server.sh`)。
2. WS 网关运行在 `8010` 端口(`scripts/run_ws_service.sh`)。
3.`.env` 中设置 `WORKER_BASE_URL` 指向 Worker 地址(例如 `http://127.0.0.1:8000` 或内网地址)。
### Docker 快速部署(推荐)
1. 启动调度服务容器:
```bash
cd video_worker
cp .env.example .env
bash scripts/run_edge_dispatch_docker.sh
```
2. 检查健康状态:
```bash
curl http://127.0.0.1:8020/health
```
3. 在边缘设备上运行客户端(连接调度服务并执行本地 Worker
```bash
cd video_worker
. .venv/bin/activate
export DISPATCH_WS_URL=ws://<dispatch-host>:8020/ws/edge/edge-a4000-01
export WORKER_BASE_URL=http://127.0.0.1:8000
python scripts/edge_device_client.py
```
4. 外部系统触发生成HTTP
```bash
curl -X POST http://<dispatch-host>:8020/dispatch/generate \
-H "Content-Type: application/json" \
-d '{
"device_id": "edge-a4000-01",
"request": {
"prompt": "a lonely man walking in a rainy neon street, cinematic, handheld camera",
"negative_prompt": "blurry, deformed face, extra limbs, flicker",
"quality_mode": "preview",
"duration_sec": 1,
"width": 320,
"height": 240,
"fps": 8,
"steps": 8,
"seed": 123456
}
}'
```
5. 查询调度状态:
```bash
curl http://<dispatch-host>:8020/dispatch/<dispatch_id>
```
## 9. 常见问题
- `ffmpeg not found`