mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 15:18:24 +00:00
fix(transcode): preserve trashed status during background jobs and handle permanent purge (#416)
* fix(transcode): preserve trashed status during background jobs and handle permanent purge * fix(workflow): clear heartbeat and add info logs on task cancellation * fix(transcode): terminate media processes and guard task activities on cancellation - Pass AbortSignal to ffmpeg and pdftoppm child processes in transcodeService to terminate processes on task cancellation - Add local task AbortController context and cancellation guards in executeActivity to prevent subsequent workflow activities - Forward taskId and cancellation signals in transcode, screenshot, and PDF activities - Use updateMany instead of update in task activities to eliminate Prisma P2025 errors on purged task records * fix(workflow): allow cleanup activities in finally blocks during task cancellation Remove blanket cancellation check in executeActivity so that workflows can execute cleanup and failure handling activities in catch and finally blocks upon cancellation, while relying on AbortSignal in active activities to abort execution. * docs(changelog): improve user friendliness of changelog entries and formatting example * docs(agents): update changelog guidelines to emphasize end-user friendly descriptions * fix(transcode): handle queued cancellation and delete races in media workflow
This commit is contained in:
@@ -16,9 +16,9 @@ export async function fetchAssetWithKey(workerQueue: string, assetId: string) {
|
||||
const { getAssetActivity } = getActivities()
|
||||
const asset = await executeActivity(workerQueue, getAssetActivity, assetId)
|
||||
const key = asset?.storageKey?.key
|
||||
if (!asset || !key) {
|
||||
if (!asset || !key || asset.status === 'pending_purge') {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Asset not found or has no key',
|
||||
message: 'Asset not found, has no key, or is being purged',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ describe('renderPdfPagesWorkflow', () => {
|
||||
await renderPdfPagesWorkflow(task)
|
||||
|
||||
expect(mockActivities.renderPdfPagesActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-pdf-pages',
|
||||
assetKey: 'doc.pdf',
|
||||
assetId: 'asset-pdf',
|
||||
start: 1,
|
||||
|
||||
@@ -21,6 +21,7 @@ export async function renderPdfPagesWorkflow(task: WorkflowTask): Promise<void>
|
||||
const pdfKey = (asset.media as PrismaJson.MediaInfo | null)?.pdfTranscode?.key || key
|
||||
|
||||
const pages = await executeActivity(workerQueue, renderPdfPagesActivity, {
|
||||
taskId: task.id,
|
||||
assetKey: pdfKey,
|
||||
assetId: asset.id,
|
||||
start: payload.pdfPages.start,
|
||||
|
||||
@@ -87,6 +87,7 @@ describe('takeVideoScreenshotsWorkflow', () => {
|
||||
await takeVideoScreenshotsWorkflow(task)
|
||||
|
||||
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-screenshot',
|
||||
assetKey: 'video.mp4',
|
||||
assetId: 'asset-video',
|
||||
start: 0,
|
||||
@@ -157,6 +158,7 @@ describe('takeVideoScreenshotsWorkflow', () => {
|
||||
await takeVideoScreenshotsWorkflow(task)
|
||||
|
||||
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-screenshot-proxy',
|
||||
assetKey: 'proxy-1080p.mp4',
|
||||
assetId: 'asset-video-proxy',
|
||||
start: 1.2345,
|
||||
|
||||
@@ -33,6 +33,7 @@ export async function takeVideoScreenshotsWorkflow(task: WorkflowTask): Promise<
|
||||
const { takeScreenshotsActivity } = getActivities()
|
||||
|
||||
const screenshots = await executeActivity(workerQueue, takeScreenshotsActivity, {
|
||||
taskId: task.id,
|
||||
assetKey: targetKey,
|
||||
assetId: asset.id,
|
||||
start: payload.screenshot.start,
|
||||
|
||||
@@ -304,11 +304,13 @@ describe('transcodeVideoWorkflow', () => {
|
||||
|
||||
await transcodeVideoWorkflow(task)
|
||||
|
||||
expect(mockActivities.transcodeAudioActivity).toHaveBeenCalledWith({
|
||||
assetKey: 'audio.wav',
|
||||
filePath: '/tmp/video.mp4',
|
||||
threads: 4,
|
||||
})
|
||||
expect(mockActivities.transcodeAudioActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
assetKey: 'audio.wav',
|
||||
filePath: '/tmp/video.mp4',
|
||||
threads: 4,
|
||||
}),
|
||||
)
|
||||
|
||||
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
|
||||
assetId: 'asset-audio',
|
||||
@@ -390,6 +392,7 @@ describe('transcodeVideoWorkflow', () => {
|
||||
posterSpec: {
|
||||
key: 'files/asset-poster/poster.webp',
|
||||
},
|
||||
taskId: 'task-poster',
|
||||
})
|
||||
|
||||
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
|
||||
|
||||
@@ -68,6 +68,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
const posterResult = await executeActivity(workerQueue, extractPosterActivity, {
|
||||
assetKey: key,
|
||||
posterSpec,
|
||||
taskId: task.id,
|
||||
})
|
||||
mediaInfo.poster = posterResult.poster
|
||||
await executeActivity(workerQueue, updateAssetMediaActivity, {
|
||||
@@ -98,6 +99,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
}
|
||||
|
||||
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
|
||||
taskId: task.id,
|
||||
assetKey: key,
|
||||
filePath,
|
||||
videoSpec,
|
||||
@@ -119,6 +121,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
const isAudio = mediaInfo.proxyType === 'audio'
|
||||
if (isAudio && metadata) {
|
||||
const audioTranscode = await executeActivity(workerQueue, transcodeAudioActivity, {
|
||||
taskId: task.id,
|
||||
assetKey: key,
|
||||
filePath,
|
||||
threads: spec.threads,
|
||||
@@ -150,6 +153,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
}
|
||||
|
||||
const spriteResult = await executeActivity(workerQueue, generateSpriteActivity, {
|
||||
taskId: task.id,
|
||||
assetKey: key,
|
||||
filePath,
|
||||
spriteSpec,
|
||||
|
||||
Reference in New Issue
Block a user