docs: 同步任务执行文档

This commit is contained in:
meijiali
2026-07-03 11:12:34 +08:00
parent 9bad7b6e63
commit c612afd217
3 changed files with 1269 additions and 37 deletions
+37 -37
View File
@@ -101,13 +101,13 @@ pyproject.toml
**步骤**
- [ ] 创建 `app/``app/services/``app/platforms/``app/templates/``app/static/``tests/` 目录。
- [ ] 添加 FastAPI、SQLAlchemy、Pydantic、httpx、Jinja2、pytest、respx、beautifulsoup4 等依赖。
- [ ]`app/main.py` 中创建 FastAPI 应用。
- [ ] 实现 `/health`,返回 `{ "status": "ok" }`
- [ ] 编写 `tests/unit/test_config.py`,覆盖默认配置和环境变量读取。
- [ ] 编写 `/health` 集成测试。
- [ ] 运行 `pytest tests/unit tests/integration -q`
- [x] 创建 `app/``app/services/``app/platforms/``app/templates/``app/static/``tests/` 目录。
- [x] 添加 FastAPI、SQLAlchemy、Pydantic、httpx、Jinja2、pytest、respx、beautifulsoup4 等依赖。
- [x]`app/main.py` 中创建 FastAPI 应用。
- [x] 实现 `/health`,返回 `{ "status": "ok" }`
- [x] 编写 `tests/unit/test_config.py`,覆盖默认配置和环境变量读取。
- [x] 编写 `/health` 集成测试。
- [x] 运行 `pytest tests/unit tests/integration -q`
**验收**
@@ -145,13 +145,13 @@ pyproject.toml
**步骤**
- [ ] 先写配置默认值测试。
- [ ] 实现 Pydantic Settings 或等价配置类。
- [ ] 校验 `AI_CONCURRENCY` 默认值为 2,硬上限不超过 3。
- [ ] 校验 `AI_MAX_RETRIES` 默认值为 3。
- [ ] 补充 `.env.example`
- [ ] 写测试:`CRAWL_PAGE_INTERVAL_SECONDS` 可从环境变量读取,默认值为 1.5。
- [ ]`.env.example` 中补充该配置项及注释说明。
- [x] 先写配置默认值测试。
- [x] 实现 Pydantic Settings 或等价配置类。
- [x] 校验 `AI_CONCURRENCY` 默认值为 2,硬上限不超过 3。
- [x] 校验 `AI_MAX_RETRIES` 默认值为 3。
- [x] 补充 `.env.example`
- [x] 写测试:`CRAWL_PAGE_INTERVAL_SECONDS` 可从环境变量读取,默认值为 1.5。
- [x]`.env.example` 中补充该配置项及注释说明。
**验收**
@@ -178,15 +178,15 @@ pyproject.toml
**步骤**
- [ ]`tests/unit/test_models.py`,断言所有表可创建。
- [ ] 实现 SQLAlchemy Base、engine、session。
- [ ] SQLite 启用 `check_same_thread=False``timeout=10`、WAL。
- [ ] 实现 `Base.metadata.create_all(engine)` 启动初始化。
- [ ] 实现 `tasks.analysis_status``analysis_success_rate`、进度字段。
- [ ] 实现 reports 表业务约束在应用层校验所需字段。
- [ ] 【性能预留索引,不影响功能验收】在 comments 表上添加 `(task_id, content_item_id)` 联合索引。
- [ ] 【性能预留索引,不影响功能验收】在 content_items 表上添加 `(task_id, hotspot_id)` 联合索引。
- [ ] 【性能预留索引,不影响功能验收】在 reports 表上添加 `(task_id, report_type)` 联合索引。
- [x]`tests/unit/test_models.py`,断言所有表可创建。
- [x] 实现 SQLAlchemy Base、engine、session。
- [x] SQLite 启用 `check_same_thread=False``timeout=10`、WAL。
- [x] 实现 `Base.metadata.create_all(engine)` 启动初始化。
- [x] 实现 `tasks.analysis_status``analysis_success_rate`、进度字段。
- [x] 实现 reports 表业务约束在应用层校验所需字段。
- [x] 【性能预留索引,不影响功能验收】在 comments 表上添加 `(task_id, content_item_id)` 联合索引。
- [x] 【性能预留索引,不影响功能验收】在 content_items 表上添加 `(task_id, hotspot_id)` 联合索引。
- [x] 【性能预留索引,不影响功能验收】在 reports 表上添加 `(task_id, report_type)` 联合索引。
**验收**
@@ -214,16 +214,16 @@ pyproject.toml
**步骤**
- [ ] 写创建任务 API 测试,合法参数返回 `task_id``status`
- [ ] 写非法参数测试:平台非法、热点数量越界、内容条目数越界、评论数越界。
- [ ] 实现 `CreateTaskRequest` schema。
- [ ] 实现 `ThreadPoolExecutor(max_workers=1)`
- [ ]`CreateTaskRequest` 处理逻辑中,查询当前是否存在 `status=running` 的任务;若存在,直接返回 HTTP 400,响应体为 `{"detail": "当前有正在运行的任务,请稍后再试"}`,不创建新任务。
- [ ] 写测试:当已有 `status=running` 任务时,`POST /api/tasks` 返回 400。
- [ ] 写测试:当无 running 任务时,`POST /api/tasks` 正常创建并返回 200/201。
- [ ] 创建任务时保存平台、配置规模、创建时间、状态和进度字段。
- [ ] 同一平台重复创建任务时生成独立任务。
- [ ] 实现任务列表查询。
- [x] 写创建任务 API 测试,合法参数返回 `task_id``status`
- [x] 写非法参数测试:平台非法、热点数量越界、内容条目数越界、评论数越界。
- [x] 实现 `CreateTaskRequest` schema。
- [x] 实现 `ThreadPoolExecutor(max_workers=1)`
- [x]`CreateTaskRequest` 处理逻辑中,查询当前是否存在 `status=running` 的任务;若存在,直接返回 HTTP 400,响应体为 `{"detail": "当前有正在运行的任务,请稍后再试"}`,不创建新任务。
- [x] 写测试:当已有 `status=running` 任务时,`POST /api/tasks` 返回 400。
- [x] 写测试:当无 running 任务时,`POST /api/tasks` 正常创建并返回 200/201。
- [x] 创建任务时保存平台、配置规模、创建时间、状态和进度字段。
- [x] 同一平台重复创建任务时生成独立任务。
- [x] 实现任务列表查询。
**验收**
@@ -243,10 +243,10 @@ pyproject.toml
**步骤**
- [ ] 写测试:数据库中存在 `status=running` 的任务。
- [ ] 应用 lifespan 启动时执行恢复逻辑。
- [ ] 将 running 任务更新为 failed。
- [ ] 写入 `error_stage=system``error_type=unexpected_restart``error_message=系统重启,任务被中断`
- [x] 写测试:数据库中存在 `status=running` 的任务。
- [x] 应用 lifespan 启动时执行恢复逻辑。
- [x] 将 running 任务更新为 failed。
- [x] 写入 `error_stage=system``error_type=unexpected_restart``error_message=系统重启,任务被中断`
**验收**