Add Force reset to clear stuck jobs and kill a wedged Comfy.
Settings and the header menu can cancel invisible queue/pending work and force-stop Beast when Sleep is blocked. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -483,6 +483,60 @@ export async function cancelStudioJob(owner: string, id: string) {
|
||||
return result
|
||||
}
|
||||
|
||||
/** Wipe waiting/running/held studio rows + live/pending jobs for this owner (stuck recovery). */
|
||||
export async function clearStuckStudioWork(owner: string) {
|
||||
const liveIds = new Set<string>()
|
||||
const cancelledStudio: string[] = []
|
||||
const clearedPending: string[] = []
|
||||
|
||||
for (const job of listJobs()) {
|
||||
if (job.library?.ownerKey !== owner) continue
|
||||
if (job.status === 'complete' || job.status === 'error' || job.status === 'cancelled') continue
|
||||
liveIds.add(job.id)
|
||||
job.status = 'cancelled'
|
||||
job.error = 'Cleared by force reset'
|
||||
if (job.library) {
|
||||
job.library.stopAfterCurrent = true
|
||||
job.library.queueAutoRun = false
|
||||
}
|
||||
emitJob(job, { type: 'error', error: 'Cleared by force reset', message: 'Cleared by force reset' })
|
||||
}
|
||||
|
||||
for (const pending of listPendingJobs()) {
|
||||
if (pending.ownerKey !== owner) continue
|
||||
deletePendingJob(pending.jobId)
|
||||
clearedPending.push(pending.jobId)
|
||||
}
|
||||
|
||||
const before = readJobs(owner)
|
||||
for (const job of before) {
|
||||
if (!canCancelStudioStatus(job.status)) continue
|
||||
try {
|
||||
await cancelStudioJob(owner, job.id)
|
||||
cancelledStudio.push(job.id)
|
||||
} catch {
|
||||
await mutateStore(owner, (store) => {
|
||||
const row = store.jobs.find(item => item.id === job.id)
|
||||
if (!row) return
|
||||
row.status = 'cancelled'
|
||||
row.liveJobId = undefined
|
||||
row.lastError = 'Cleared by force reset'
|
||||
row.updatedAt = Date.now()
|
||||
syncPausedFlag(store)
|
||||
}).catch(() => null)
|
||||
cancelledStudio.push(job.id)
|
||||
}
|
||||
}
|
||||
|
||||
for (const id of liveIds) deletePendingJob(id)
|
||||
|
||||
return {
|
||||
cancelledStudio: cancelledStudio.length,
|
||||
clearedPending: clearedPending.length,
|
||||
cancelledLive: liveIds.size
|
||||
}
|
||||
}
|
||||
|
||||
async function stopLiveGeneration(liveJobId?: string, shotQueueId?: string) {
|
||||
if (shotQueueId) {
|
||||
const { setQueueJob, pauseShotQueue } = await import('~/server/utils/shotQueue')
|
||||
|
||||
Reference in New Issue
Block a user