Skip to content

Commit 284ae24

Browse files
committed
fix: grant completed source reuploads a fresh generation
1 parent 4f4820f commit 284ae24

2 files changed

Lines changed: 63 additions & 3 deletions

File tree

apps/web/__tests__/unit/desktop-recording-jobs.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,51 @@ describe("retained-source retry policy", () => {
895895
});
896896

897897
describe("recovery admission", () => {
898+
it.each([null, source])(
899+
"gives a verified re-upload fresh attempts without reviving the old worker: %j",
900+
async (retainedSource) => {
901+
const old = await createAttempt();
902+
rows.jobs = [
903+
{
904+
...old,
905+
state: "source-blocked",
906+
source: retainedSource,
907+
attemptCount: 70,
908+
leaseExpiresAt: null,
909+
errorCode: "source-reupload-required",
910+
},
911+
];
912+
const resumed = await ensureSegmentProcessingJob({
913+
videoId,
914+
userId,
915+
verification: { ...verification, requiredAudio: false },
916+
});
917+
expect(resumed.created).toBe(true);
918+
expect(resumed.job.generation).not.toBe(old.generation);
919+
expect(resumed.job).toMatchObject({
920+
state: "committing",
921+
attemptCount: 0,
922+
source: null,
923+
verification: { requiredAudio: true },
924+
});
925+
expect(await heartbeatAttempt(old)).toBe(false);
926+
expect(
927+
await claimProcessingAttempt({
928+
videoId,
929+
generation: resumed.job.generation,
930+
}),
931+
).toMatchObject({ attemptCount: 1 });
932+
const repeated = await ensureSegmentProcessingJob({
933+
videoId,
934+
userId,
935+
verification,
936+
});
937+
expect(repeated.created).toBe(false);
938+
expect(repeated.job.generation).toBe(resumed.job.generation);
939+
expect(repeated.job.attemptCount).toBe(1);
940+
},
941+
);
942+
898943
it("keeps an inspected missing source paused until a completion request resumes it", async () => {
899944
const attempt = await createAttempt();
900945
const paused = {

apps/web/lib/desktop-recording-jobs.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,24 @@ export async function ensureSegmentProcessingJob({
290290
verification !== undefined &&
291291
(job.source !== null || job.verification !== null) &&
292292
!sameArtifact(verification, job);
293-
if (created || replacesArtifact) {
294-
if (replacesArtifact) {
295-
job = candidate;
293+
const resumesReupload =
294+
verification !== undefined &&
295+
job.errorCode === DESKTOP_RECORDING_SOURCE_REUPLOAD_REQUIRED;
296+
if (created || replacesArtifact || resumesReupload) {
297+
if (replacesArtifact || resumesReupload) {
298+
job =
299+
resumesReupload && !replacesArtifact && verification
300+
? {
301+
...candidate,
302+
verification: {
303+
...verification,
304+
requiredAudio:
305+
verification.requiredAudio ||
306+
job.verification?.requiredAudio === true ||
307+
job.source?.requiredAudio === true,
308+
},
309+
}
310+
: candidate;
296311
await tx
297312
.update(videoProcessingJobs)
298313
.set(job)

0 commit comments

Comments
 (0)