feat: 新增项目自动推进功能(定时调度 + 章节生成流水线)#157
Open
zhangsiqiang519 wants to merge 1 commit into
Open
Conversation
实现按 cron 表达式定时触发章节自动生成的完整流水线,支持 one-to-one
和 one-to-many 两种大纲模式,包含大纲自动生成/续写、章节结构补齐、
正文批量生成等多阶段编排。
后端新增:
- ProjectGenerationSchedule 数据模型 + Pydantic schema(expansion_strategy
收紧为 Literal 联合类型)
- REST API:GET/PUT/DELETE/POST trigger(/project-automation/{project_id})
- 调度器:30 秒轮询,PostgreSQL 使用 SELECT FOR UPDATE SKIP LOCKED
分布式锁防重复触发,SQLite 降级为普通查询
- 编排服务:collect_project_generation_state → _ensure_ready_chapters →
_select_chapters_for_generation → check_prerequisites →
_create_scheduled_batch_task → asyncio.create_task 异步执行
- 错误处理:calculate_next_run_at 统一到 Service 层(ValueError 替代
HTTPException),错误路径 fallback 延迟 1 小时重试
- Alembic 迁移(PostgreSQL + SQLite)
后端修改:
- prompt_service.format_prompt 改用 format_map(defaultdict(str)),
缺失模板参数自动以空字符串替代,防止用户自定义模板崩溃
- main.py 注册路由 + lifespan 启停调度器
- database.py / models/__init__.py 注册新模型
前端新增:
- AutoAdvancementSettings 组件:完整的自动推进配置 UI(项目选择、
Cron 可视化/高级编辑、生成策略、模型选择、状态面板、操作按钮)
- cronUtils.ts:Cron 解析/生成工具函数(从 SystemSettings 抽离)
- api.ts:projectAutomationApi(含 AbortSignal 支持)
前端修改:
- SystemSettings.tsx:新增「自动推进」Tab,引入 AutoAdvancementSettings
- App.tsx:移除未使用的 PromptWorkshop 导入
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
新增项目自动推进功能,支持按 cron 表达式定时触发章节自动生成,覆盖 one-to-one 和 one-to-many 两种大纲模式的完整流水线。
核心能力
SELECT FOR UPDATE SKIP LOCKED分布式锁防重复触发,SQLite 自动降级format_prompt改用format_map(defaultdict(str)),用户自定义模板中新增占位符不再导致崩溃calculate_next_run_at到 Service 层(ValueError替代HTTPException),错误路径 fallback 延迟 1 小时重试,避免调度卡死AutoAdvancementSettings组件,支持 Cron 可视化/高级编辑、生成策略配置、模型选择、实时状态面板新增文件
backend/app/models/project_generation_schedule.pybackend/app/schemas/project_generation_schedule.pyexpansion_strategy为Literal联合类型)backend/app/api/project_generation_schedule.pybackend/app/services/project_generation_automation_service.pybackend/app/services/project_generation_scheduler.pybackend/alembic/versions/*_新增项目自动推进计划.pyfrontend/src/components/AutoAdvancementSettings.tsxfrontend/src/utils/cronUtils.ts修改文件
backend/app/main.pybackend/app/database.pyProjectGenerationSchedule模型backend/app/models/__init__.pyProjectGenerationSchedulebackend/app/services/prompt_service.pyformat_prompt改用format_map防缺失参数崩溃frontend/src/pages/SystemSettings.tsxfrontend/src/services/api.tsprojectAutomationApi(含AbortSignal)frontend/src/App.tsxPromptWorkshop导入Test plan
PUT /api/project-automation/{project_id}创建自动推进计划,验证 cron 表达式解析和 next_run_at 计算POST /api/project-automation/{project_id}/trigger手动触发,验证大纲生成/续写 + 章节补齐 + 批量任务创建DELETE /api/project-automation/{project_id}正确删除计划expansion_strategy非法值被 Pydantic 拒绝next_run_at到期时自动触发skipped_conflictFOR UPDATE SKIP LOCKED正常工作Notes
prompt_service.format_prompt改动影响全局:所有使用该方法的地方都会受益于缺失参数的容错处理