图片生成改为每张一条并行请求,根治多图生成超时 500
根因:多图生成走一条 HTTP 串行出 N 张,4 张累计 >120s 被 gunicorn 强杀 worker → 500 (日志实锤 SystemExit on ARK response.begin)。采纳用户建议拆成「每张一条请求」: - App.tsx generateImages: 拆成 N 条并行单张请求(Promise.allSettled),单张约 30s 不超时, 并行后总耗时≈单张(比串行快 N 倍),任一张失败只丢那张(各自独立扣费/回滚) - Dockerfile: gunicorn --timeout 120→300,给慢 ARK 留余量(双保险) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -355,7 +355,21 @@ export function App() {
|
||||
}
|
||||
|
||||
function generateImages(payload: { prompt: string; mode?: "image" | "model" | "cover"; count?: number }) {
|
||||
return action(() => api.generateImage(payload), "图片已生成");
|
||||
// 每张图一条独立 HTTP 请求、并行发出(不再让一条请求串行出 N 张)——
|
||||
// 单张约 30s 不会触发后端请求超时;并行后 N 张总耗时≈单张,也不长时间占用后端进程。
|
||||
// 任一张失败只丢那一张(各自独立扣费/回滚),其余正常返回。
|
||||
const n = Math.max(1, Math.min(Number(payload.count) || 1, 12));
|
||||
return action(async () => {
|
||||
const settled = await Promise.allSettled(
|
||||
Array.from({ length: n }, () => api.generateImage({ prompt: payload.prompt, mode: payload.mode, count: 1 }))
|
||||
);
|
||||
const assets = settled.flatMap((r) => (r.status === "fulfilled" ? r.value.assets : []));
|
||||
if (assets.length === 0) {
|
||||
const firstErr = settled.find((r) => r.status === "rejected") as PromiseRejectedResult | undefined;
|
||||
throw new Error(firstErr ? String((firstErr.reason as Error)?.message || firstErr.reason || "生成失败") : "未生成任何图片");
|
||||
}
|
||||
return { assets };
|
||||
}, "图片已生成");
|
||||
}
|
||||
|
||||
function onAuthed(payload: { token: string; user: User; team: Team }) {
|
||||
|
||||
Reference in New Issue
Block a user