🎥 Make videos programmatically with React
show which chunks are missing
Jonny Burger84bb3f443e56
diff --git a/packages/lambda/src/functions/helpers/create-post-render-data.ts b/packages/lambda/src/functions/helpers/create-post-render-data.tsindex 754ef83946..3dd155cae6 100644--- a/packages/lambda/src/functions/helpers/create-post-render-data.ts+++ b/packages/lambda/src/functions/helpers/create-post-render-data.ts@@ -118,7 +118,8 @@ export const createPostRenderData = ({retriesInfo,mostExpensiveFrameRanges: getMostExpensiveChunks(parsedTimings,- renderMetadata.framesPerLambda+ renderMetadata.framesPerLambda,+ renderMetadata.frameRange[1]),};};diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.tsindex 1581543bdf..ca3ccd76db 100644--- a/packages/lambda/src/functions/helpers/get-progress.ts+++ b/packages/lambda/src/functions/helpers/get-progress.ts@@ -12,7 +12,6 @@ import {renderMetadataKey,rendersPrefix,} from '../../shared/constants';-import {DOCS_URL} from '../../shared/docs-url';import {calculateChunkTimes} from './calculate-chunk-times';import {estimatePriceFromBucket} from './calculate-price-from-bucket';import {checkIfRenderExists} from './check-if-render-exists';@@ -33,6 +32,7 @@ import {getRetryStats} from './get-retry-stats';import {getTimeToFinish} from './get-time-to-finish';import {inspectErrors} from './inspect-errors';import {lambdaLs} from './io';+import {makeTimeoutError} from './make-timeout-error';import type {EnhancedErrorInfo} from './write-lambda-error';export const getProgress = async ({@@ -240,19 +240,7 @@ export const getProgress = async ({const allErrors: EnhancedErrorInfo[] = [isBeyondTimeout- ? ({- attempt: 1,- chunk: null,- explanation: `The main function timed out after ${timeoutInMilliseconds}ms. Consider increasing the timeout of your function. You can use the "--timeout" parameter when deploying a function via CLI, or the "timeoutInSeconds" parameter when using the deployFunction API. ${DOCS_URL}/docs/lambda/cli/functions#deploy`,- frame: null,- isFatal: true,- s3Location: '',- stack: new Error().stack,- tmpDir: null,- totalAttempts: 1,- type: 'stitcher',- willRetry: false,- } as EnhancedErrorInfo)+ ? makeTimeoutError({timeoutInMilliseconds, renderMetadata, chunks}): null,...errorExplanations,].filter(Internals.truthy);diff --git a/packages/lambda/src/functions/helpers/make-timeout-error.ts b/packages/lambda/src/functions/helpers/make-timeout-error.tsnew file mode 100644index 0000000000..05e67405a2--- /dev/null+++ b/packages/lambda/src/functions/helpers/make-timeout-error.ts@@ -0,0 +1,63 @@+import type {_Object} from '@aws-sdk/client-s3';+import type {RenderMetadata} from '../../defaults';+import {DOCS_URL} from '../../shared/docs-url';+import {parseLambdaChunkKey} from '../../shared/parse-chunk-key';+import type {EnhancedErrorInfo} from './write-lambda-error';++export const makeTimeoutError = ({+ timeoutInMilliseconds,+ chunks,+ renderMetadata,+}: {+ timeoutInMilliseconds: number;+ chunks: _Object[];+ renderMetadata: RenderMetadata;+}): EnhancedErrorInfo => {+ const availableChunks = chunks.map((c) =>+ parseLambdaChunkKey(c.Key as string)+ );++ const missingChunks = new Array(renderMetadata.totalChunks)+ .fill(true)+ .filter((_, i) => {+ return !availableChunks.find((c) => c.chunk === i);+ })+ .map((_, i) => i);++ const missingChunksMessageList = missingChunks+ .map((ch) => {+ const isLastChunk = ch === renderMetadata.totalChunks - 1;+ const start = ch * renderMetadata.framesPerLambda;+ const end = isLastChunk+ ? renderMetadata.frameRange[1]+ : (ch + 1) * renderMetadata.framesPerLambda - 1;++ return `Chunk ${ch} (Frames ${start} - ${end})`;+ })+ .slice(0, 5)+ .join(', ');++ const message = [+ `The main function timed out after ${timeoutInMilliseconds}ms.`,+ `Consider increasing the timeout of your function.`,+ `The following chunks are missing (showing up to 5): ${missingChunksMessageList}.`,+ `You can use the "--timeout" parameter when deploying a function via CLI, or the "timeoutInSeconds" parameter when using the deployFunction() API.`,+ `${DOCS_URL}/docs/lambda/cli/functions#deploy`,+ ].join('\n');++ return {+ attempt: 1,+ chunk: null,+ explanation: message,+ frame: null,+ isFatal: true,+ s3Location: '',+ stack: new Error().stack as string,+ tmpDir: null,+ totalAttempts: 1,+ type: 'stitcher',+ willRetry: false,+ message,+ name: 'TimeoutError',+ };+};diff --git a/packages/lambda/src/shared/get-most-expensive-chunks.ts b/packages/lambda/src/shared/get-most-expensive-chunks.tsindex 37489675cc..9916043031 100644--- a/packages/lambda/src/shared/get-most-expensive-chunks.ts+++ b/packages/lambda/src/shared/get-most-expensive-chunks.ts@@ -10,7 +10,8 @@ export type ExpensiveChunk = {export const getMostExpensiveChunks = (parsedTimings: ParsedTiming[],- framesPerLambda: number+ framesPerLambda: number,+ lastFrame: number): ExpensiveChunk[] => {const mostExpensiveChunks = parsedTimings.slice(0)@@ -23,12 +24,14 @@ export const getMostExpensiveChunks = (.slice(0, 5);return mostExpensiveChunks.map((c) => {+ const isLastChunk = c.chunk === parsedTimings.length - 1;+return {timeInMilliseconds: c.rendered - c.start,chunk: c.chunk,frameRange: [framesPerLambda * c.chunk,- framesPerLambda * (c.chunk + 1) - 1,+ isLastChunk ? lastFrame : framesPerLambda * (c.chunk + 1) - 1,],};});diff --git a/packages/lambda/src/test/unit/most-expensive-chunks.test.ts b/packages/lambda/src/test/unit/most-expensive-chunks.test.tsindex 5745790fc5..1ca3f2d3a5 100644--- a/packages/lambda/src/test/unit/most-expensive-chunks.test.ts+++ b/packages/lambda/src/test/unit/most-expensive-chunks.test.ts@@ -48,7 +48,8 @@ test('Should calculate most expensive chunks', () => {renderId: 'abc',},],- 10+ 10,+ 99);expect(most).toEqual([