🎥 Make videos programmatically with React
fix display bug showing lambda launch time being negative
Jonny Burger52c6f322a88d
diff --git a/packages/lambda/src/functions/helpers/create-post-render-data.ts b/packages/lambda/src/functions/helpers/create-post-render-data.tsindex a611e13e6b..f0c4e37774 100644--- a/packages/lambda/src/functions/helpers/create-post-render-data.ts+++ b/packages/lambda/src/functions/helpers/create-post-render-data.ts@@ -84,11 +84,14 @@ export const createPostRenderData = ({.map((c) => c.Size ?? 0).reduce((a, b) => a + b, 0);- const {timeToInvokeLambdas} = getLambdasInvokedStats(+ const {timeToInvokeLambdas} = getLambdasInvokedStats({contents,renderId,- renderMetadata.startedDate- );+ estimatedRenderLambdaInvokations:+ renderMetadata.estimatedRenderLambdaInvokations,+ startDate: renderMetadata.startedDate,+ checkIfAllLambdasWereInvoked: false,+ });const retriesInfo = getRetryStats({contents, renderId});if (timeToInvokeLambdas === null) {diff --git a/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts b/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.tsindex b021dc0098..a136b57fdd 100644--- a/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts+++ b/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts@@ -1,5 +1,6 @@import type {_Object} from '@aws-sdk/client-s3';import {lambdaInitializedPrefix} from '../../shared/constants';+import {parseLambdaInitializedKey} from '../../shared/parse-lambda-initialized-key';import {max} from './min-max';export type LambdaInvokeStats = {@@ -7,20 +8,33 @@ export type LambdaInvokeStats = {lambdasInvoked: number;};-export const getLambdasInvokedStats = (- contents: _Object[],- renderId: string,- startDate: number | null-): LambdaInvokeStats => {- const lambdasInvoked = contents.filter((c) =>- c.Key?.startsWith(lambdaInitializedPrefix(renderId))- );+export const getLambdasInvokedStats = ({+ contents,+ renderId,+ estimatedRenderLambdaInvokations,+ startDate,+ checkIfAllLambdasWereInvoked,+}: {+ contents: _Object[];+ renderId: string;+ estimatedRenderLambdaInvokations: number | null;+ startDate: number | null;+ checkIfAllLambdasWereInvoked: boolean;+}): LambdaInvokeStats => {+ const lambdasInvoked = contents+ .filter((c) => c.Key?.startsWith(lambdaInitializedPrefix(renderId)))+ .filter((c) => parseLambdaInitializedKey(c.Key as string).attempt === 1);++ const allLambdasInvoked =+ !checkIfAllLambdasWereInvoked &&+ lambdasInvoked.length === estimatedRenderLambdaInvokations;const timeToInvokeLambdas =- startDate === null+ !allLambdasInvoked || startDate === null? null: (max(lambdasInvoked.map((l) => l.LastModified?.getTime() as number)) ??0) - startDate;+return {timeToInvokeLambdas,lambdasInvoked: lambdasInvoked.length,diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.tsindex b2801ad7dd..593457a492 100644--- a/packages/lambda/src/functions/helpers/get-progress.ts+++ b/packages/lambda/src/functions/helpers/get-progress.ts@@ -177,11 +177,14 @@ export const getProgress = async ({.map((c) => c.Size ?? 0).reduce((a, b) => a + b, 0);- const lambdasInvokedStats = getLambdasInvokedStats(+ const lambdasInvokedStats = getLambdasInvokedStats({contents,renderId,- renderMetadata?.startedDate ?? null- );+ estimatedRenderLambdaInvokations:+ renderMetadata?.estimatedRenderLambdaInvokations ?? null,+ startDate: renderMetadata?.startedDate ?? null,+ checkIfAllLambdasWereInvoked: true,+ });const retriesInfo = getRetryStats({contents,diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.tsindex d5baeec371..6e24a83043 100644--- a/packages/lambda/src/functions/launch.ts+++ b/packages/lambda/src/functions/launch.ts@@ -378,11 +378,14 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {framesEncoded: frameCount.length,totalFrames: frameCount.length,doneIn: encodingStop ? encodingStop - encodingStart : null,- timeToInvoke: getLambdasInvokedStats(+ timeToInvoke: getLambdasInvokedStats({contents,- params.renderId,- renderMetadata.startedDate- ).timeToInvokeLambdas,+ renderId: params.renderId,+ estimatedRenderLambdaInvokations:+ renderMetadata.estimatedRenderLambdaInvokations,+ checkIfAllLambdasWereInvoked: false,+ startDate: renderMetadata.startedDate,+ }).timeToInvokeLambdas,};const finalEncodingProgressProm = lambdaWriteFile({bucketName: params.bucketName,