Keep a generation log so wiped or failed jobs can be re-queued.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-03 16:15:09 -05:00
co-authored by Cursor
parent b5014f02b4
commit 88c5d25b78
10 changed files with 421 additions and 18 deletions
+31 -2
View File
@@ -389,17 +389,34 @@ export async function addStudioJob(params: {
jobs.push(job)
return job
})
void import('~/server/utils/generationLog')
.then(({ recordGenerationQueued }) => recordGenerationQueued({
ownerKey: params.ownerKey,
studioJobId: job.id,
kind,
payload: params.payload
}))
.catch(() => null)
return job
}
export async function patchStudioJob(owner: string, id: string, patch: (job: StudioJob) => void) {
return mutate(owner, (jobs) => {
const updated = await mutate(owner, (jobs) => {
const job = jobs.find(item => item.id === id)
if (!job) throw createError({ statusCode: 404, statusMessage: 'Queued job not found' })
patch(job)
job.updatedAt = Date.now()
return structuredClone(job)
})
if (updated.status === 'error' || updated.status === 'running' || updated.status === 'cancelled' || updated.status === 'complete') {
void import('~/server/utils/generationLog')
.then(({ updateGenerationLogByStudioJob }) => updateGenerationLogByStudioJob(owner, id, {
status: updated.status === 'running' ? 'running' : updated.status,
lastError: updated.lastError
}))
.catch(() => null)
}
return updated
}
function canCancelStudioStatus(status: StudioJobStatus) {
@@ -460,6 +477,9 @@ export async function cancelStudioJob(owner: string, id: string) {
}
}
kickStudioQueue()
void import('~/server/utils/generationLog')
.then(({ updateGenerationLogByStudioJob }) => updateGenerationLogByStudioJob(owner, id, { status: 'cancelled' }))
.catch(() => null)
return result
}
@@ -598,7 +618,7 @@ export async function markStudioHeld(owner: string, id: string) {
}
export async function markStudioSettled(owner: string, liveJobId: string, status: 'complete' | 'error' | 'cancelled', error?: string) {
return mutate(owner, (jobs) => {
const settled = await mutate(owner, (jobs) => {
const job = jobs.find(item => item.liveJobId === liveJobId)
if (!job) return null
if (job.holdForCutIn && status === 'complete') {
@@ -615,6 +635,15 @@ export async function markStudioSettled(owner: string, liveJobId: string, status
job.updatedAt = Date.now()
return structuredClone(job)
})
if (settled) {
void import('~/server/utils/generationLog')
.then(({ updateGenerationLogByStudioJob }) => updateGenerationLogByStudioJob(owner, settled.id, {
status: settled.status === 'held' ? 'queued' : status,
lastError: error
}))
.catch(() => null)
}
return settled
}
function pickCutIn(jobs: StudioJob[]) {