Skip to content

🎥 Make videos programmatically with React

delete invoke progress last

Jonny Burgera375915dad8b
diff --git a/packages/lambda/remotionlambda.zip b/packages/lambda/remotionlambda.zip
index 33ceb1a8ca..d8f163e078 100644
Binary files a/packages/lambda/remotionlambda.zip and b/packages/lambda/remotionlambda.zip differ
diff --git a/packages/lambda/src/functions/helpers/delete-chunks.ts b/packages/lambda/src/functions/helpers/delete-chunks.ts
index 22e280ccac..71a41fd0ee 100644
--- a/packages/lambda/src/functions/helpers/delete-chunks.ts
+++ b/packages/lambda/src/functions/helpers/delete-chunks.ts
@@ -1,31 +1,25 @@
import {_Object} from '@aws-sdk/client-s3';
import {AwsRegion} from '../..';
import {cleanItems} from '../../api/clean-items';
-import {getFilesToDelete} from './get-files-to-delete';
+import {CleanupJob} from './get-files-to-delete';
export const deleteChunks = async ({
- renderId,
- chunkCount,
bucket,
region,
contents,
+ jobs,
}: {
- renderId: string;
- chunkCount: number;
bucket: string;
region: AwsRegion;
contents: _Object[];
+ jobs: CleanupJob[];
}) => {
const start = Date.now();
- const toDelete = getFilesToDelete({
- chunkCount,
- renderId,
- });
await cleanItems({
bucket,
region,
- list: toDelete.map((item) => {
+ list: jobs.map((item) => {
if (item.type === 'exact') {
return item.name;
}
diff --git a/packages/lambda/src/functions/helpers/get-files-to-delete.ts b/packages/lambda/src/functions/helpers/get-files-to-delete.ts
index da571fa8c9..4a7f8da04d 100644
--- a/packages/lambda/src/functions/helpers/get-files-to-delete.ts
+++ b/packages/lambda/src/functions/helpers/get-files-to-delete.ts
@@ -5,16 +5,27 @@ import {
lambdaTimingsPrefixForChunk,
} from '../../shared/constants';
+export type CleanupJob = {
+ name: string;
+ type: 'exact' | 'prefix';
+};
+
+export const getFinalFileToDelete = (renderId: string): CleanupJob[] => {
+ return [
+ {
+ name: encodingProgressKey(renderId),
+ type: 'exact',
+ },
+ ];
+};
+
export const getFilesToDelete = ({
chunkCount,
renderId,
}: {
chunkCount: number;
renderId: string;
-}): {
- name: string;
- type: 'exact' | 'prefix';
-}[] => {
+}): CleanupJob[] => {
const initialized = new Array(chunkCount).fill(true).map((x, i) =>
lambdaInitializedKey({
chunk: i,
@@ -49,9 +60,5 @@ export const getFilesToDelete = ({
type: 'prefix' as const,
};
}),
- {
- name: encodingProgressKey(renderId),
- type: 'exact',
- },
];
};
diff --git a/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts b/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts
index a312a79d54..4c648e1a27 100644
--- a/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts
+++ b/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts
@@ -13,7 +13,6 @@ export const getLambdasInvokedStats = (
);
const allLambdasInvoked = lambdasInvoked.length === estimatedInvokations;
- // TODO: Doesn't work while in cleanup, progress goes backwards
const timeToInvokeLambdas =
allLambdasInvoked && startDate
? RenderInternals.max(
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index 6ac3bdefd0..3526907bc3 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -32,6 +32,10 @@ import {createPostRenderData} from './helpers/create-post-render-data';
import {deleteChunks} from './helpers/delete-chunks';
import {closeBrowser, getBrowserInstance} from './helpers/get-browser-instance';
import {getCurrentRegionInFunction} from './helpers/get-current-region';
+import {
+ getFilesToDelete,
+ getFinalFileToDelete,
+} from './helpers/get-files-to-delete';
import {inspectErrors} from './helpers/inspect-errors';
import {lambdaLs, lambdaWriteFile} from './helpers/io';
import {timer} from './helpers/timer';
@@ -261,6 +265,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
key: outName(params.renderId, params.codec),
body: fs.createReadStream(outfile),
region: getCurrentRegionInFunction(),
+ // TODO: Allow to make private
acl: 'public-read',
expectedBucketOwner: options.expectedBucketOwner,
});
@@ -310,12 +315,16 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
expectedBucketOwner: options.expectedBucketOwner,
});
+ const jobs = getFilesToDelete({
+ chunkCount,
+ renderId: params.renderId,
+ });
+
const deletProm = deleteChunks({
region: getCurrentRegionInFunction(),
- renderId: params.renderId,
bucket: params.bucketName,
- chunkCount,
contents,
+ jobs,
});
const postRenderData = createPostRenderData({
@@ -337,7 +346,21 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
region: getCurrentRegionInFunction(),
renderId: params.renderId,
});
- await Promise.all([cleanupChunksProm, fs.promises.rm(outfile)]);
+ // This file will be deleted last, if we delete it before,
+ // The invoke progress timing info returned by getRenderProgress() will go
+ // backwards
+ const encodingDelete = deleteChunks({
+ region: getCurrentRegionInFunction(),
+ bucket: params.bucketName,
+ contents,
+ jobs: getFinalFileToDelete(params.renderId),
+ });
+
+ await Promise.all([
+ cleanupChunksProm,
+ encodingDelete,
+ fs.promises.rm(outfile),
+ ]);
};
export const launchHandler = async (