Implement FastAPI Temporal MVP pipeline

This commit is contained in:
Codex
2026-03-27 00:10:28 +08:00
commit cc03da8a94
52 changed files with 3619 additions and 0 deletions

169
README.md Normal file
View File

@@ -0,0 +1,169 @@
# FastAPI + Temporal MVP 图片流水线
这是一个最小可运行的图片生产流水线 MVP使用 `FastAPI + Temporal + SQLite + SQLAlchemy` 实现,当前所有图像处理步骤都为 mock。
## 功能范围
- 低端全自动流程 `auto_basic`
- 中端半自动流程 `semi_pro`
- 创建订单、查询订单、查询资产、提交审核、查询 workflow 状态接口
- 中端流程支持 `review signal`
- 中端流程支持 `rerun_face / rerun_fusion / rerun_scene`
- 提供 `.env.example`、Alembic 初始迁移、基础测试
## 环境要求
- Python 3.11+
- Temporal CLI 或可用的 Temporal Server
## 安装依赖
```bash
python -m venv .venv
.venv\Scripts\activate
python -m pip install -U pip
python -m pip install -e .
```
## 环境变量
复制示例环境变量:
```bash
copy .env.example .env
```
默认数据库:
- `sqlite+aiosqlite:///./temporal_demo.db`
## 启动 Temporal Server
```bash
temporal server start-dev
```
## 初始化数据库
推荐先执行 Alembic 迁移:
```bash
alembic upgrade head
```
如果没有先迁移API 启动时也会在 `AUTO_CREATE_TABLES=true` 下自动建表,方便本地 MVP 调试。
## 启动 FastAPI
```bash
uvicorn app.main:app --reload
```
健康检查:
```bash
curl http://127.0.0.1:8000/healthz
```
## 启动 Worker
```bash
python -m app.workers.runner
```
## API 调用示例
### 创建低端订单
```bash
curl -X POST http://127.0.0.1:8000/api/v1/orders ^
-H "Content-Type: application/json" ^
-d "{\"customer_level\":\"low\",\"service_mode\":\"auto_basic\",\"model_id\":101,\"pose_id\":3,\"garment_asset_id\":9001,\"scene_ref_asset_id\":8001}"
```
### 创建中端订单
```bash
curl -X POST http://127.0.0.1:8000/api/v1/orders ^
-H "Content-Type: application/json" ^
-d "{\"customer_level\":\"mid\",\"service_mode\":\"semi_pro\",\"model_id\":101,\"pose_id\":3,\"garment_asset_id\":9001,\"scene_ref_asset_id\":8001}"
```
### 查询订单详情
```bash
curl http://127.0.0.1:8000/api/v1/orders/1
```
### 查询订单资产
```bash
curl http://127.0.0.1:8000/api/v1/orders/1/assets
```
### 查询待审核列表
```bash
curl http://127.0.0.1:8000/api/v1/reviews/pending
```
### 提交审核通过
```bash
curl -X POST http://127.0.0.1:8000/api/v1/reviews/1/submit ^
-H "Content-Type: application/json" ^
-d "{\"decision\":\"approve\",\"reviewer_id\":77,\"comment\":\"通过\"}"
```
### 提交 rerun_face
```bash
curl -X POST http://127.0.0.1:8000/api/v1/reviews/1/submit ^
-H "Content-Type: application/json" ^
-d "{\"decision\":\"rerun_face\",\"reviewer_id\":77,\"comment\":\"面部不自然,重跑 face\"}"
```
### 查询 workflow 状态
```bash
curl http://127.0.0.1:8000/api/v1/workflows/1
```
## 流程说明
### 低端 `auto_basic`
1. `prepare_model`
2. `tryon`
3. `scene`
4. `qc`
5. `export`
### 中端 `semi_pro`
1. `prepare_model`
2. `tryon`
3. `scene`
4. `texture`
5. `face`
6. `fusion`
7. `qc`
8. 进入 `waiting_review`
9. `approve` 后进入 `export`
10. `rerun_scene` 回到 `scene`
11. `rerun_face` 回到 `face`
12. `rerun_fusion` 回到 `fusion`
## 测试
```bash
pytest
```
覆盖范围:
- 健康检查
- 低端流程跑通
- 中端流程进入 `waiting_review`
- 中端流程审核通过
- 中端流程 rerun 分支回流