({
videoId,
rawFileKey,
processingMessage,
mode,
forceRestart,
}: {
videoId: Video.VideoId;
rawFileKey: string;
processingMessage: string;
mode?: "singlepart" | "multipart";
forceRestart?: boolean;
})
| 38 | } |
| 39 | |
| 40 | export async function transitionVideoToProcessing({ |
| 41 | videoId, |
| 42 | rawFileKey, |
| 43 | processingMessage, |
| 44 | mode, |
| 45 | forceRestart, |
| 46 | }: { |
| 47 | videoId: Video.VideoId; |
| 48 | rawFileKey: string; |
| 49 | processingMessage: string; |
| 50 | mode?: "singlepart" | "multipart"; |
| 51 | forceRestart?: boolean; |
| 52 | }): Promise<VideoProcessingStartStatus> { |
| 53 | const result = await db() |
| 54 | .update(videoUploads) |
| 55 | .set({ |
| 56 | ...(mode ? { mode } : {}), |
| 57 | phase: "processing", |
| 58 | processingProgress: 0, |
| 59 | processingMessage, |
| 60 | processingError: null, |
| 61 | rawFileKey, |
| 62 | updatedAt: new Date(), |
| 63 | }) |
| 64 | .where( |
| 65 | forceRestart |
| 66 | ? eq(videoUploads.videoId, videoId) |
| 67 | : and( |
| 68 | eq(videoUploads.videoId, videoId), |
| 69 | ne(videoUploads.phase, "processing"), |
| 70 | // "complete" is terminal for implicit starts: a multipart |
| 71 | // completion retried after an uncertain network outcome can |
| 72 | // land after the first processing run already finished, and |
| 73 | // must not kick off a duplicate full re-process. Explicit |
| 74 | // re-processing goes through forceRestart. |
| 75 | ne(videoUploads.phase, "complete"), |
| 76 | ), |
| 77 | ); |
| 78 | |
| 79 | if (getAffectedRows(result) > 0) { |
| 80 | return "started"; |
| 81 | } |
| 82 | |
| 83 | const [upload] = await db() |
| 84 | .select() |
| 85 | .from(videoUploads) |
| 86 | .where(eq(videoUploads.videoId, videoId)); |
| 87 | |
| 88 | if (!upload) { |
| 89 | throw new Error("No upload record found"); |
| 90 | } |
| 91 | |
| 92 | if (upload.phase === "processing") { |
| 93 | return "already-processing"; |
| 94 | } |
| 95 | |
| 96 | if (upload.phase === "complete") { |
| 97 | return "already-complete"; |
no test coverage detected