Stop cancelled video jobs from coming back after delete.

A leftover process-remaining wake was flipping the row back to running or error, so Remove looked like it did nothing.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-08-30 12:47:59 -05:00
co-authored by Cursor
parent 201eb1107f
commit c88a8494d5
5 changed files with 80 additions and 29 deletions
+24 -3
View File
@@ -58,6 +58,7 @@ export interface ShotQueue {
const writeChains = new Map<string, Promise<unknown>>()
const activeJobs = new Map<string, string>()
const cancelledQueueIds = new Set<string>()
function libraryRoot() {
const config = useRuntimeConfig()
@@ -135,9 +136,23 @@ export function queueIsProcessing(id: string) {
return activeJobs.has(id)
}
export function markShotQueueCancelled(id: string) {
if (!id) return
cancelledQueueIds.add(id)
activeJobs.delete(id)
}
export function isShotQueueCancelled(id: string) {
return Boolean(id) && cancelledQueueIds.has(id)
}
export function setQueueJob(id: string, jobId: string | null) {
if (jobId) activeJobs.set(id, jobId)
else activeJobs.delete(id)
if (jobId) {
if (cancelledQueueIds.has(id)) return
activeJobs.set(id, jobId)
} else {
activeJobs.delete(id)
}
}
export function getQueueJobId(id: string) {
@@ -229,6 +244,9 @@ export async function createShotQueue(params: {
}
export async function updateShotQueue(owner: string, id: string, patch: (queue: ShotQueue) => void) {
if (cancelledQueueIds.has(id)) {
throw createError({ statusCode: 410, statusMessage: 'This batch was removed' })
}
return mutate(owner, (queues) => {
const queue = queues.find(item => item.id === id)
if (!queue) throw createError({ statusCode: 404, statusMessage: 'Queue not found' })
@@ -314,6 +332,9 @@ export async function syncQueueFromJob(job: Job, clipId?: string) {
}
export async function prepareQueueBurst(owner: string, id: string, count: number | 'all') {
if (cancelledQueueIds.has(id)) {
throw createError({ statusCode: 410, statusMessage: 'This batch was removed' })
}
return mutate(owner, (queues) => {
const queue = queues.find(item => item.id === id)
if (!queue) throw createError({ statusCode: 404, statusMessage: 'Queue not found' })
@@ -418,7 +439,7 @@ export async function deleteShotQueue(owner: string, id: string, options: { forc
if (!options.force && activeJobs.has(id)) {
throw createError({ statusCode: 409, statusMessage: 'Stop this batch before deleting it' })
}
activeJobs.delete(id)
markShotQueueCancelled(id)
return mutate(owner, (queues) => {
const index = queues.findIndex(item => item.id === id)
if (index < 0) throw createError({ statusCode: 404, statusMessage: 'Queue not found' })