mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 19:07:41 +00:00
refactor(workflow): enforce strict nested type safety for WorkflowTaskPayload
This commit is contained in:
@@ -216,7 +216,7 @@ describe('TranscodeService', () => {
|
||||
})
|
||||
|
||||
it('should create transcode tasks correctly', async () => {
|
||||
const task = (await transcodeService.createVideoTranscodeTask('asset-123', {
|
||||
const task = (await transcodeService.createVideoTranscodeTask('asset-123', 'proj-123', {
|
||||
videoStrategy: 'single',
|
||||
thumbnail: true,
|
||||
})) as WorkflowTask
|
||||
@@ -224,7 +224,7 @@ describe('TranscodeService', () => {
|
||||
expect(task.assetId).toBe('asset-123')
|
||||
expect(task.type).toBe('transcode')
|
||||
expect(task.status).toBe('pending')
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
expect((task.payload as any).videoStrategy).toBe('single')
|
||||
expect(task.payload?.projectId).toBe('proj-123')
|
||||
expect(task.payload?.transcode?.videoStrategy).toBe('single')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -400,26 +400,32 @@ export class TranscodeService {
|
||||
|
||||
// --- Task Creation Helpers ---
|
||||
|
||||
async createVideoTranscodeTask(assetId: string, spec: PrismaJson.TaskSpec) {
|
||||
async createVideoTranscodeTask(assetId: string, projectId: string, spec: PrismaJson.TaskSpec) {
|
||||
return this.prismaClient.workflowTask.create({
|
||||
data: {
|
||||
assetId,
|
||||
projectId,
|
||||
type: WorkflowTaskType.transcode,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
payload: spec as any,
|
||||
payload: {
|
||||
projectId,
|
||||
transcode: spec,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async createImageTranscodeTask(assetId: string, spec: PrismaJson.TaskSpec) {
|
||||
async createImageTranscodeTask(assetId: string, projectId: string, spec: PrismaJson.TaskSpec) {
|
||||
return this.prismaClient.workflowTask.create({
|
||||
data: {
|
||||
assetId,
|
||||
projectId,
|
||||
type: WorkflowTaskType.transcode,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
payload: spec as any,
|
||||
payload: {
|
||||
projectId,
|
||||
transcode: spec,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ export class VideoTranscoder {
|
||||
projectId: this.projectId,
|
||||
type: WorkflowTaskType.transcode,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
payload: this.spec,
|
||||
payload: {
|
||||
projectId: this.projectId,
|
||||
transcode: this.spec,
|
||||
},
|
||||
},
|
||||
})
|
||||
return task.id
|
||||
@@ -75,7 +78,10 @@ export class ImageTranscoder {
|
||||
projectId: this.projectId,
|
||||
type: WorkflowTaskType.transcode,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
payload: this.spec,
|
||||
payload: {
|
||||
projectId: this.projectId,
|
||||
transcode: this.spec,
|
||||
},
|
||||
},
|
||||
})
|
||||
return task.id
|
||||
|
||||
@@ -74,8 +74,11 @@ describe('Transcode Workflow', () => {
|
||||
status: WorkflowTaskStatus.pending,
|
||||
output: null,
|
||||
payload: {
|
||||
videoStrategy: 'single',
|
||||
thumbnail: true,
|
||||
projectId: 'proj-1',
|
||||
transcode: {
|
||||
videoStrategy: 'single',
|
||||
thumbnail: true,
|
||||
},
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
@@ -138,7 +141,9 @@ describe('Transcode Workflow', () => {
|
||||
type: WorkflowTaskType.transcode,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
output: null,
|
||||
payload: {},
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
|
||||
Reference in New Issue
Block a user