Design APIs for Long-Running Jobs
Added 2026-10
Design APIs for Long-Running Jobs — Chinese original prompt
这个接口要跑 [耗时范围],经常被网关超时掐断。请把它改成提交任务返回任务标识、由客户端轮询或等回调的方式,并处理重复提交与结果过期。输出:接口时序、任务状态机、轮询建议间隔与退避、结果文件的保留时长、以及客户端拿到失败后该如何重试。
Site original
Chinese original
Example
Sample input
这个导出接口要跑两分钟,常被网关超时掐断,改成提交任务再轮询查询结果。
The output should include
- 交代接口时序与任务状态机
- 处理重复提交与结果过期问题
- 给轮询间隔退避与失败重试
Replace these placeholders 1
Swap the bracketed parts for your own details before sending.
[耗时范围]
How to use
轮询接口要能区分「还在跑」和「查不到这个任务」,否则客户端会无限重试。
Try tweaking it
- Have it restate requirements and constraints before writing code.
- Ask for the smallest change plus a rollback path, not a full-file rewrite.
What you should get
- A minimal, runnable change with copy-ready code
- Impact list: which files and call sites must follow
Common mistakes
- Asking it to touch ten files at once, then losing track of what broke what.
- Pasting only the error, with no code or version, and getting an unfixable answer.
How to check the output
- The change runs, can be rolled back, and touches nothing unrelated.
- Edge cases (empty, oversized, concurrent) are covered or explained.
Where it works
- Good for: having it restate requirements and constraints, then propose the smallest runnable change.
- Watch out: include versions and a minimal reproduction with the error, or the fix may look plausible but not fit.