mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 19:04:23 +00:00
fix(asset): mark asset as failed and display failure state in webui when transcoding fails (#445)
* fix(asset): mark asset as failed and display failure state in webui when transcoding fails * fix(transcode): do not mark asset as failed if media processing already succeeded * test(workflow): add e2e test for video transcode failure status transition * fix(webui): update failed file card badge to top-right Transcoding Failed label with error tooltip
This commit is contained in:
@@ -48,6 +48,72 @@ describe('Task Activities', () => {
|
||||
expect(updated?.status).toBe(AssetStatus.processing)
|
||||
})
|
||||
|
||||
it('should update asset status to failed and store truncated error message in media', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'test-fail.mp4',
|
||||
storageKey: { create: { key: 'test-fail.mp4' } },
|
||||
status: AssetStatus.processing,
|
||||
type: 'file',
|
||||
media: {
|
||||
original: null,
|
||||
videoTranscodes: [],
|
||||
imageTranscodes: [],
|
||||
duration: 10,
|
||||
filesize: 1000,
|
||||
frames: 300,
|
||||
finishedAt: '',
|
||||
metadata: null,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const longError = 'x'.repeat(600)
|
||||
await updateAssetStatusActivity({
|
||||
assetId: asset.id,
|
||||
status: AssetStatus.failed,
|
||||
error: longError,
|
||||
})
|
||||
|
||||
const updated = await prisma.asset.findUnique({ where: { id: asset.id } })
|
||||
expect(updated?.status).toBe(AssetStatus.failed)
|
||||
const media = updated?.media as PrismaJson.MediaInfo
|
||||
expect(media?.error).toBe('x'.repeat(500))
|
||||
expect(media?.duration).toBe(10)
|
||||
})
|
||||
|
||||
it('should NOT overwrite processed status or inject error when asset is already processed', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'already-processed.mp4',
|
||||
storageKey: { create: { key: 'already-processed.mp4' } },
|
||||
status: AssetStatus.processed,
|
||||
type: 'file',
|
||||
media: {
|
||||
original: null,
|
||||
videoTranscodes: [],
|
||||
imageTranscodes: [],
|
||||
duration: 10,
|
||||
filesize: 1000,
|
||||
frames: 300,
|
||||
finishedAt: '2026-01-01T00:00:00Z',
|
||||
metadata: null,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await updateAssetStatusActivity({
|
||||
assetId: asset.id,
|
||||
status: AssetStatus.failed,
|
||||
error: 'Some post-transcode error',
|
||||
})
|
||||
|
||||
const updated = await prisma.asset.findUnique({ where: { id: asset.id } })
|
||||
expect(updated?.status).toBe(AssetStatus.processed)
|
||||
const media = updated?.media as PrismaJson.MediaInfo
|
||||
expect(media?.error).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should NOT overwrite trashed status when asset is soft-deleted (isDeleted: true)', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
|
||||
@@ -82,9 +82,34 @@ export async function updateTaskStatusActivity(params: UpdateTaskStatusParams):
|
||||
export interface UpdateAssetStatusParams {
|
||||
assetId: string
|
||||
status: AssetStatus
|
||||
error?: string
|
||||
}
|
||||
|
||||
export async function updateAssetStatusActivity(params: UpdateAssetStatusParams): Promise<void> {
|
||||
if (params.status === AssetStatus.failed) {
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: params.assetId },
|
||||
select: { media: true, status: true },
|
||||
})
|
||||
// Never overwrite an asset that has already completed media processing
|
||||
if (asset?.status === AssetStatus.processed) {
|
||||
return
|
||||
}
|
||||
const data: Prisma.AssetUpdateInput = { status: params.status }
|
||||
if (params.error !== undefined) {
|
||||
const existingMedia = (asset?.media as PrismaJson.MediaInfo | null) || {}
|
||||
data.media = {
|
||||
...existingMedia,
|
||||
error: params.error.slice(0, 500),
|
||||
} as PrismaJson.MediaInfo
|
||||
}
|
||||
await prisma.asset.updateMany({
|
||||
where: { id: params.assetId, isDeleted: false, status: { not: AssetStatus.processed } },
|
||||
data,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await prisma.asset.updateMany({
|
||||
where: { id: params.assetId, isDeleted: false },
|
||||
data: { status: params.status },
|
||||
|
||||
Reference in New Issue
Block a user