Stop a deleted video chain from keeping the GPU.
Interrupt now clears Comfy, and a missing shot list no longer continues to the next extension. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,24 +1,55 @@
|
||||
import { pauseShotQueue, setQueueJob } from '~/server/utils/shotQueue'
|
||||
import { emitJob, getJob, listJobs } from '~/server/utils/jobs'
|
||||
import { interruptComfy } from '~/server/utils/comfy'
|
||||
import { deletePendingJob } from '~/server/utils/pending'
|
||||
import { assertLibraryOwner, removeExtendTemp } from '~/server/utils/library'
|
||||
import { markShotQueueCancelled, pauseShotQueue, setQueueJob } from '~/server/utils/shotQueue'
|
||||
import { cancelStudioJob, listStudioJobs } from '~/server/utils/studioQueue'
|
||||
|
||||
function stopLiveJob(job: NonNullable<ReturnType<typeof getJob>>) {
|
||||
job.status = 'cancelled'
|
||||
job.error = 'Job interrupted.'
|
||||
emitJob(job, { type: 'status', message: 'Cancelling job...' })
|
||||
removeExtendTemp(job.library?.extendTmpDir)
|
||||
if (job.library) {
|
||||
job.library.stopAfterCurrent = true
|
||||
job.library.queueAutoRun = false
|
||||
job.library.chainContinuing = false
|
||||
if (job.library.queueId) {
|
||||
markShotQueueCancelled(job.library.queueId)
|
||||
setQueueJob(job.library.queueId, null)
|
||||
}
|
||||
}
|
||||
deletePendingJob(job.id)
|
||||
emitJob(job, { type: 'error', error: 'Job interrupted.', message: 'Job interrupted.' })
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{ jobId?: string; kind?: string }>(event).catch(() => ({}))
|
||||
const jobId = String(body?.jobId || '')
|
||||
const job = jobId ? getJob(jobId) : undefined
|
||||
if (job) {
|
||||
job.status = 'cancelled'
|
||||
emitJob(job, { type: 'status', message: 'Cancelling job...' })
|
||||
removeExtendTemp(job.library?.extendTmpDir)
|
||||
if (job.library?.queueId) {
|
||||
job.library.stopAfterCurrent = true
|
||||
job.library.queueAutoRun = false
|
||||
const kind = String(body?.kind || '')
|
||||
const named = jobId ? getJob(jobId) : undefined
|
||||
const targets = named
|
||||
? [named]
|
||||
: listJobs().filter((job) => {
|
||||
if (job.status === 'complete' || job.status === 'error' || job.status === 'cancelled') return false
|
||||
if (kind === 'edit') return job.kind === 'edit'
|
||||
if (kind === 'video') return job.kind !== 'edit'
|
||||
return true
|
||||
})
|
||||
for (const job of targets) {
|
||||
stopLiveJob(job)
|
||||
if (job.library?.queueId && job.library.ownerKey) {
|
||||
await pauseShotQueue(job.library.ownerKey, job.library.queueId).catch(() => null)
|
||||
setQueueJob(job.library.queueId, null)
|
||||
}
|
||||
}
|
||||
if (jobId) deletePendingJob(jobId)
|
||||
const ok = await interruptComfy()
|
||||
if (job) {
|
||||
emitJob(job, { type: 'error', error: 'Job interrupted.', message: 'Job interrupted.' })
|
||||
const { owner } = assertLibraryOwner(event)
|
||||
for (const row of listStudioJobs(owner)) {
|
||||
if (row.status !== 'running' && row.status !== 'held') continue
|
||||
if (kind === 'edit' && row.kind !== 'edit') continue
|
||||
if (kind === 'video' && row.kind === 'edit') continue
|
||||
await cancelStudioJob(owner, row.id).catch(() => null)
|
||||
}
|
||||
return { ok }
|
||||
const ok = await interruptComfy()
|
||||
return { ok, cancelled: targets.length }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user