Summary
A user-facing task platform that isolates a customer worker through a database contract while providing task, quota, payment, and admin workflows.
Business Value
Delivered a testable user-facing task platform while keeping the customer worker integration isolated through the database contract.
Engineering Depth
Covers layered FastAPI services, async SQLAlchemy, PostgreSQL triggers, LISTEN/NOTIFY, SSE, quota ledgers, payment callbacks, React feature modules, and automated regression.
Evidence
本地仓库 README / docs/架构说明 / docs/交付文档 / apps/api / apps/web / tests
Repository · Confidence High · Verified 2026-05-17
- Evidence level: strict review (core sections only show verifiable metrics)
- Source type: Repository / code records
- Source link: no public link provided, review against delivery records
- Verified at: 2026-05-17 (31 days ago, fresh evidence)
Rationale: High confidence: organized under strict evidence rules, traceable to repository or code records, verified 31 days ago.
Background
用户需要提交论文检索任务并跟踪结果,但真正执行检索的 Worker 由甲方维护,只通过共享数据库表与平台对接。
Challenge
异步任务跨系统执行,状态同步、终态契约、结果链接安全和额度扣减都需要由平台侧兜住,否则容易出现进度不可见、终态回退或重复扣费。
Action and Results
Solution
- 用户侧闭环:交付登录注册、任务工作台、结果下载、个人中心、额度流水、支付升级和管理后台。
- Worker 契约:使用 Alembic 迁移加入 check constraint 与触发器,约束状态流转、终态完成时间和成功任务结果数。
- 状态同步:通过 PostgreSQL
pg_notify + asyncpg LISTEN 唤醒 SSE,前端保留轮询兜底。 - 额度治理:成功任务再扣减额度,结合
SELECT ... FOR UPDATE、唯一额度事件和测试覆盖处理并发。
Result
形成测试验收版论文检索任务平台,覆盖用户认证、任务提交、进度同步、结果下载、额度流水、支付宝升级和管理后台。
Key Signals
使用 FastAPI、SQLAlchemy、Alembic、PostgreSQL、Redis 和 React/Vite 搭建用户端、管理端、任务、支付和额度模块。 通过数据库约束与触发器固化 Worker 对 `tasks` 表的状态回写契约,禁止终态回退并要求成功任务具备结果数。 实现 LISTEN/NOTIFY、按任务 SSE、多任务 SSE、全局活动任务 SSE 与轮询兜底,让用户侧能持续感知检索进度。 将任务额度扣减延后到成功完成后执行,并通过锁、唯一额度事件和并发测试避免失败任务或重复通知误扣。 Tech Stack
PythonFastAPIAsyncIOSQLAlchemyPostgreSQLRedisAlembicReact 19TypeScriptViteSSEPlaywright