🎥 Make videos programmatically with React
timing profile
Jonny Burger16c41004ac84
diff --git a/packages/lambda/src/functions/chunk-optimization/write-profile.ts b/packages/lambda/src/functions/chunk-optimization/write-profile.tsindex ce6c8f4212..72f67be7e1 100644--- a/packages/lambda/src/functions/chunk-optimization/write-profile.ts+++ b/packages/lambda/src/functions/chunk-optimization/write-profile.ts@@ -17,7 +17,7 @@ export const writeTimingProfile = async ({await lambdaWriteFile({bucketName,body: JSON.stringify(data),- key: timingProfileName(renderId) + Date.now() + '.json',+ key: timingProfileName(renderId),region: getCurrentRegion(),acl: 'private',expectedBucketOwner,diff --git a/packages/lambda/src/functions/get-progress.ts b/packages/lambda/src/functions/get-progress.tsindex ee5c3b54b9..31b1d6a0f1 100644--- a/packages/lambda/src/functions/get-progress.ts+++ b/packages/lambda/src/functions/get-progress.ts@@ -7,7 +7,7 @@ import {EncodingProgress,encodingProgressKey,getErrorKeyPrefix,- lambdaInitializedKey,+ lambdaInitializedPrefix,LambdaPayload,LambdaRoutines,lambdaTimingsPrefix,@@ -160,10 +160,6 @@ export const progressHandler = async (c.Key?.startsWith(chunkKey(lambdaParams.renderId)));- const lambdasInvoked = contents.filter((c) =>- c.Key?.startsWith(lambdaInitializedKey(lambdaParams.renderId))- ).length;-const finishedTimings = contents.filter((c) =>c.Key?.startsWith(lambdaTimingsPrefix(lambdaParams.renderId)));@@ -256,10 +252,17 @@ export const progressHandler = async (}/${outName(lambdaParams.renderId, renderMetadata.codec)}`;};+ const lambdasInvoked = getOutputFile()+ ? renderMetadata?.totalChunks ?? 0+ : contents.filter((c) =>+ c.Key?.startsWith(lambdaInitializedPrefix(lambdaParams.renderId))+ ).length;+const cleanup = getCleanupProgress({chunkCount: renderMetadata?.totalChunks ?? 0,- chunks,+ contents,output: getOutputFile(),+ renderId: lambdaParams.renderId,});return {diff --git a/packages/lambda/src/functions/helpers/delete-chunks.ts b/packages/lambda/src/functions/helpers/delete-chunks.tsindex 7ad46fae9f..ff0497e2db 100644--- a/packages/lambda/src/functions/helpers/delete-chunks.ts+++ b/packages/lambda/src/functions/helpers/delete-chunks.ts@@ -1,6 +1,6 @@import {AwsRegion} from '../..';import {cleanItems} from '../../api/clean-items';-import {chunkKeyForIndex} from '../../shared/constants';+import {getFilesToDelete} from './get-files-to-delete';export const deleteChunks = async ({renderId,@@ -13,12 +13,10 @@ export const deleteChunks = async ({bucket: string;region: AwsRegion;}) => {- const toDelete = new Array(chunkCount).fill(true).map((x, i) =>- chunkKeyForIndex({- index: i,- renderId,- })- );+ const toDelete = getFilesToDelete({+ chunkCount,+ renderId,+ });await cleanItems({bucket,diff --git a/packages/lambda/src/functions/helpers/get-cleanup-progress.ts b/packages/lambda/src/functions/helpers/get-cleanup-progress.tsindex 1390f5a6a4..2db788198b 100644--- a/packages/lambda/src/functions/helpers/get-cleanup-progress.ts+++ b/packages/lambda/src/functions/helpers/get-cleanup-progress.ts@@ -1,14 +1,18 @@import {_Object} from '@aws-sdk/client-s3';+import {getFilesToDelete} from './get-files-to-delete';export const getCleanupProgress = ({- chunks,+ contents,output,chunkCount,+ renderId,}: {- chunks: _Object[];+ contents: _Object[];output: string | null;chunkCount: number;+ renderId: string;}): null | {+ filesToDelete: number;filesDeleted: number;done: boolean;} => {@@ -16,10 +20,16 @@ export const getCleanupProgress = ({return null;}- const filesDeleted = chunkCount - chunks.length;+ const filesToDelete = getFilesToDelete({chunkCount, renderId});+ const filesStillThere = contents.filter((c) =>+ filesToDelete.includes(c.Key as string)+ );++ const filesDeleted = filesToDelete.length - filesStillThere.length;return {+ filesToDelete: filesToDelete.length,filesDeleted,- done: chunks.length === 0,+ done: filesStillThere.length === 0,};};diff --git a/packages/lambda/src/functions/helpers/get-files-to-delete.ts b/packages/lambda/src/functions/helpers/get-files-to-delete.tsnew file mode 100644index 0000000000..ee1e89a814--- /dev/null+++ b/packages/lambda/src/functions/helpers/get-files-to-delete.ts@@ -0,0 +1,27 @@+import {+ chunkKeyForIndex,+ encodingProgressKey,+ lambdaInitializedKey,+} from '../../shared/constants';++export const getFilesToDelete = ({+ chunkCount,+ renderId,+}: {+ chunkCount: number;+ renderId: string;+}) => {+ const initialized = new Array(chunkCount).fill(true).map((x, i) =>+ lambdaInitializedKey({+ chunk: i,+ renderId,+ })+ );+ const chunks = new Array(chunkCount).fill(true).map((x, i) =>+ chunkKeyForIndex({+ index: i,+ renderId,+ })+ );+ return [...initialized, ...chunks, encodingProgressKey(renderId)];+};diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.tsindex 22efc13996..f85bf1aa34 100644--- a/packages/lambda/src/functions/renderer.ts+++ b/packages/lambda/src/functions/renderer.ts@@ -97,7 +97,10 @@ const renderHandler = async (params: LambdaPayload, options: Options) => {tmpSize: getFolderSizeRecursively('/tmp'),tmpDirFiles: getFolderFiles('/tmp'),}),- key: `${lambdaInitializedKey(params.renderId)}-${params.chunk}.txt`,+ key: lambdaInitializedKey({+ renderId: params.renderId,+ chunk: params.chunk,+ }),region: getCurrentRegion(),expectedBucketOwner: options.expectedBucketOwner,});diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.tsindex c826aa8089..80fc3adea2 100644--- a/packages/lambda/src/shared/constants.ts+++ b/packages/lambda/src/shared/constants.ts@@ -28,8 +28,15 @@ export const encodingProgressKey = (renderId: string) =>`${rendersPrefix(renderId)}/encoding-progress.json`;export const renderMetadataKey = (renderId: string) =>`${rendersPrefix(renderId)}/render-metadata.json`;-export const lambdaInitializedKey = (renderId: string) =>+export const lambdaInitializedPrefix = (renderId: string) =>`${rendersPrefix(renderId)}/lambda-initialized`;+export const lambdaInitializedKey = ({+ renderId,+ chunk,+}: {+ renderId: string;+ chunk: number;+}) => `${lambdaInitializedPrefix(renderId)}-${chunk}.txt`;export const lambdaTimingsPrefix = (renderId: string) =>`${rendersPrefix(renderId)}/lambda-timings`;export const lambdaTimingsKey = ({@@ -56,7 +63,7 @@ export const chunkKeyForIndex = ({index: number;}) => `${chunkKey(renderId)}${String(index).padStart(8, '0')}`;export const timingProfileName = (renderId: string) =>- `${rendersPrefix(renderId)}/timing-profile`;+ `${rendersPrefix(renderId)}/timing-profile.json`;export const getErrorKeyPrefix = (renderId: string) =>`${rendersPrefix(renderId)}/errors/`;export const optimizationProfile = (siteId: string, compositionId: string) =>