Fix generation progress getting stuck at 1% after Comfy finishes.
Poll Comfy history and the job snapshot so the browser still gets the video when the live stream is buffered or the websocket misses completion. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
export default defineEventHandler((event) => {
|
||||
const id = getRouterParam(event, 'id')
|
||||
const job = id ? getJob(id) : undefined
|
||||
if (!job) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Job not found' })
|
||||
}
|
||||
return jobSnapshot(job)
|
||||
})
|
||||
@@ -5,22 +5,18 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Job not found' })
|
||||
}
|
||||
|
||||
setResponseHeaders(event, {
|
||||
'Cache-Control': 'no-cache, no-store, no-transform',
|
||||
'X-Accel-Buffering': 'no',
|
||||
Connection: 'keep-alive'
|
||||
})
|
||||
|
||||
const stream = createEventStream(event)
|
||||
const send = async (payload: unknown) => {
|
||||
await stream.push(JSON.stringify(payload))
|
||||
}
|
||||
|
||||
await send({
|
||||
type: 'hello',
|
||||
status: job.status,
|
||||
message: job.message,
|
||||
progress: job.progress,
|
||||
step: job.step,
|
||||
maxStep: job.maxStep,
|
||||
promptId: job.promptId,
|
||||
elapsedMs: Date.now() - job.startedAt
|
||||
})
|
||||
|
||||
await send(jobSnapshot(job))
|
||||
for (const past of job.events) {
|
||||
await send(past)
|
||||
}
|
||||
@@ -33,7 +29,12 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
})
|
||||
|
||||
const ping = setInterval(() => {
|
||||
void send(jobSnapshot(job))
|
||||
}, 1000)
|
||||
|
||||
stream.onClosed(() => {
|
||||
clearInterval(ping)
|
||||
unsubscribe()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user