mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 14:57:13 +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:
@@ -38,14 +38,31 @@ export async function completeTask(
|
||||
})
|
||||
}
|
||||
|
||||
export async function failTask(workerQueue: string, taskId: string, err: unknown) {
|
||||
const { updateTaskStatusActivity } = getActivities()
|
||||
export async function failTask(
|
||||
workerQueue: string,
|
||||
taskId: string,
|
||||
err: unknown,
|
||||
assetId?: string,
|
||||
) {
|
||||
const { updateTaskStatusActivity, updateAssetStatusActivity } = getActivities()
|
||||
if (workerQueue) {
|
||||
const errorMsg = err instanceof Error ? err.message : String(err)
|
||||
await executeActivity(workerQueue, updateTaskStatusActivity, {
|
||||
taskId,
|
||||
status: 'failed',
|
||||
output: { error: err instanceof Error ? err.message : String(err) },
|
||||
output: { error: errorMsg },
|
||||
})
|
||||
if (assetId) {
|
||||
try {
|
||||
await executeActivity(workerQueue, updateAssetStatusActivity, {
|
||||
assetId,
|
||||
status: 'failed',
|
||||
error: errorMsg,
|
||||
})
|
||||
} catch (assetErr) {
|
||||
console.error('Failed to update asset status to failed:', assetErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
export async function transcodeImageWorkflow(task: WorkflowTask): Promise<void> {
|
||||
let tmpDir: string | undefined
|
||||
let workerQueue = ''
|
||||
let mediaProcessed = false
|
||||
|
||||
try {
|
||||
workerQueue = await getWorkerQueueAndStartTask(task)
|
||||
@@ -90,6 +91,7 @@ export async function transcodeImageWorkflow(task: WorkflowTask): Promise<void>
|
||||
assetId: asset.id,
|
||||
status: 'processed',
|
||||
})
|
||||
mediaProcessed = true
|
||||
|
||||
await executeActivity(workerQueue, createEmbeddingTaskIfEnabledActivity, {
|
||||
assetId: asset.id,
|
||||
@@ -106,7 +108,7 @@ export async function transcodeImageWorkflow(task: WorkflowTask): Promise<void>
|
||||
await completeTask(workerQueue, task.id)
|
||||
} catch (err) {
|
||||
console.error(`transcodeImageWorkflow failed for task ${task.id}:`, err)
|
||||
await failTask(workerQueue, task.id, err)
|
||||
await failTask(workerQueue, task.id, err, mediaProcessed ? undefined : task.assetId)
|
||||
throw err
|
||||
} finally {
|
||||
await cleanupTmpDir(workerQueue, tmpDir)
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
export async function transcodePdfWorkflow(task: WorkflowTask): Promise<void> {
|
||||
let tmpDir: string | undefined
|
||||
let workerQueue = ''
|
||||
let mediaProcessed = false
|
||||
|
||||
try {
|
||||
workerQueue = await getWorkerQueueAndStartTask(task)
|
||||
@@ -101,6 +102,7 @@ export async function transcodePdfWorkflow(task: WorkflowTask): Promise<void> {
|
||||
assetId: asset.id,
|
||||
status: 'processed',
|
||||
})
|
||||
mediaProcessed = true
|
||||
|
||||
await executeActivity(workerQueue, createEmbeddingTaskIfEnabledActivity, {
|
||||
assetId: asset.id,
|
||||
@@ -117,7 +119,7 @@ export async function transcodePdfWorkflow(task: WorkflowTask): Promise<void> {
|
||||
await completeTask(workerQueue, task.id)
|
||||
} catch (err) {
|
||||
console.error(`transcodePdfWorkflow failed for task ${task.id}:`, err)
|
||||
await failTask(workerQueue, task.id, err)
|
||||
await failTask(workerQueue, task.id, err, mediaProcessed ? undefined : task.assetId)
|
||||
throw err
|
||||
} finally {
|
||||
await cleanupTmpDir(workerQueue, tmpDir)
|
||||
|
||||
@@ -874,4 +874,129 @@ describe('transcodeVideoWorkflow', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('should mark task and asset as failed when an activity fails', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-fail',
|
||||
assetId: 'asset-fail',
|
||||
type: WorkflowTaskType.transcode_video,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
transcode: { videoStrategy: 'best_match' },
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
uid: 'task-uid',
|
||||
model: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
}
|
||||
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'asset-fail',
|
||||
name: 'fail.mp4',
|
||||
storageKey: { key: 'files/asset-fail/fail.mp4' },
|
||||
status: AssetStatus.uploading,
|
||||
})
|
||||
|
||||
mockActivities.getMediaInfoActivity.mockRejectedValue(new Error('FFprobe failed to read media'))
|
||||
|
||||
await expect(transcodeVideoWorkflow(task)).rejects.toThrow('FFprobe failed to read media')
|
||||
|
||||
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-fail',
|
||||
status: 'failed',
|
||||
output: { error: 'FFprobe failed to read media' },
|
||||
})
|
||||
|
||||
expect(mockActivities.updateAssetStatusActivity).toHaveBeenCalledWith({
|
||||
assetId: 'asset-fail',
|
||||
status: 'failed',
|
||||
error: 'FFprobe failed to read media',
|
||||
})
|
||||
})
|
||||
|
||||
it('should mark task as failed but keep asset as processed when post-transcode activity fails', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-post-fail',
|
||||
assetId: 'asset-post-fail',
|
||||
type: WorkflowTaskType.transcode_video,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
transcode: { videoStrategy: 'best_match' },
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
uid: 'task-uid',
|
||||
model: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
}
|
||||
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'asset-post-fail',
|
||||
name: 'video.mp4',
|
||||
storageKey: { key: 'files/asset-post-fail/video.mp4' },
|
||||
status: AssetStatus.uploading,
|
||||
mediaType: 'video/mp4',
|
||||
})
|
||||
|
||||
mockActivities.getMediaInfoActivity.mockResolvedValue({
|
||||
proxyType: 'video',
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
bitRate: 1000,
|
||||
hasAudio: false,
|
||||
format: {},
|
||||
},
|
||||
videoTranscodes: [],
|
||||
imageTranscodes: [],
|
||||
})
|
||||
|
||||
mockActivities.transcodeVideoActivity.mockResolvedValue({
|
||||
key: 'v.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
})
|
||||
|
||||
mockActivities.createEmbeddingTaskIfEnabledActivity.mockRejectedValue(
|
||||
new Error('Embedding creation failed'),
|
||||
)
|
||||
|
||||
await expect(transcodeVideoWorkflow(task)).rejects.toThrow('Embedding creation failed')
|
||||
|
||||
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-post-fail',
|
||||
status: 'failed',
|
||||
output: { error: 'Embedding creation failed' },
|
||||
})
|
||||
|
||||
expect(mockActivities.updateAssetStatusActivity).toHaveBeenCalledWith({
|
||||
assetId: 'asset-post-fail',
|
||||
status: 'processed',
|
||||
})
|
||||
|
||||
expect(mockActivities.updateAssetStatusActivity).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
status: 'failed',
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void> {
|
||||
let tmpDir: string | undefined
|
||||
let workerQueue = ''
|
||||
let mediaProcessed = false
|
||||
|
||||
try {
|
||||
workerQueue = await getWorkerQueueAndStartTask(task)
|
||||
@@ -265,6 +266,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
assetId: asset.id,
|
||||
status: 'processed',
|
||||
})
|
||||
mediaProcessed = true
|
||||
|
||||
await executeActivity(workerQueue, createEmbeddingTaskIfEnabledActivity, {
|
||||
assetId: asset.id,
|
||||
@@ -281,7 +283,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
await completeTask(workerQueue, task.id)
|
||||
} catch (err) {
|
||||
console.error(`transcodeVideoWorkflow failed for task ${task.id}:`, err)
|
||||
await failTask(workerQueue, task.id, err)
|
||||
await failTask(workerQueue, task.id, err, mediaProcessed ? undefined : task.assetId)
|
||||
throw err
|
||||
} finally {
|
||||
await cleanupTmpDir(workerQueue, tmpDir)
|
||||
|
||||
Reference in New Issue
Block a user