Skip to content

Commit

Permalink
alright
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger committed Jan 6, 2025
1 parent 10d1e43 commit 7d74dfa
Show file tree
Hide file tree
Showing 30 changed files with 189 additions and 149 deletions.
2 changes: 2 additions & 0 deletions packages/lambda/src/api/get-render-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
awsImplementation,
type AwsProvider,
} from '../functions/aws-implementation';
import {serverAwsImplementation} from '../functions/aws-server-implementation';
import {parseFunctionName} from '../functions/helpers/parse-function-name';
import type {AwsRegion} from '../regions';
import type {RenderProgress} from '../shared/constants';
Expand Down Expand Up @@ -51,6 +52,7 @@ export const getRenderProgress = async (
memorySizeInMb: parsed.memorySizeInMb,
timeoutInMilliseconds: parsed.timeoutInSeconds * 1000,
functionName: input.functionName,
serverProviderSpecifics: serverAwsImplementation,
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/lambda/src/api/render-still-on-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {wrapWithErrorHandling} from '@remotion/renderer/error-handling';
import type {
CostsInfo,
ReceivedArtifact,
RenderStillLambdaResponsePayload,
RenderStillFunctionResponsePayload,
} from '@remotion/serverless';
import type {OutNameInput, Privacy} from '@remotion/serverless/client';
import {
Expand Down Expand Up @@ -87,7 +87,7 @@ const internalRenderStillOnLambda = async (
try {
const payload = await makeLambdaRenderStillPayload(input);
const res = await new Promise<
RenderStillLambdaResponsePayload<AwsProvider>
RenderStillFunctionResponsePayload<AwsProvider>
>((resolve, reject) => {
awsImplementation
.callFunctionStreaming<ServerlessRoutines.still>({
Expand Down
8 changes: 0 additions & 8 deletions packages/lambda/src/functions/aws-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ export const awsImplementation: ProviderSpecifics<AwsProvider> = {
callFunctionAsync: callFunctionAsyncImplementation,
callFunctionStreaming: callFunctionWithStreamingImplementation,
callFunctionSync: callFunctionSyncImplementation,
getCurrentFunctionName() {
const name = process.env.AWS_LAMBDA_FUNCTION_NAME;
if (!name) {
throw new Error('Expected AWS_LAMBDA_FUNCTION_NAME to be set');
}

return name;
},
getEphemeralStorageForPriceCalculation() {
// We cannot determine the ephemeral storage size, so we
// overestimate the price, but will only have a miniscule effect (~0.2%)
Expand Down
7 changes: 7 additions & 0 deletions packages/lambda/src/functions/aws-server-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ export const serverAwsImplementation: ServerProviderSpecifics = {
return generateRandomHashWithLifeCycleRule({deleteAfter, randomHashFn});
},
deleteTmpDir: () => Promise.resolve(deleteTmpDir()),
getCurrentFunctionName: () => {
if (!process.env.AWS_LAMBDA_FUNCTION_NAME) {
throw new Error('Expected AWS_LAMBDA_FUNCTION_NAME to be set');
}

return process.env.AWS_LAMBDA_FUNCTION_NAME;
},
};
12 changes: 6 additions & 6 deletions packages/lambda/src/test/mock-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ export const mockImplementation: ProviderSpecifics<AwsProvider> = {
callFunctionAsync: getMockCallFunctionAsync,
callFunctionStreaming: getMockCallFunctionStreaming,
callFunctionSync: getMockCallFunctionSync,
getCurrentFunctionName: () =>
speculateFunctionName({
diskSizeInMb: 10240,
memorySizeInMb: 3009,
timeoutInSeconds: 120,
}),
estimatePrice,
getOutputUrl: () => {
return {
Expand All @@ -182,4 +176,10 @@ export const mockServerImplementation: ServerProviderSpecifics = {
}),
deleteTmpDir: () => Promise.resolve(),
generateRandomId: randomHashImplementation,
getCurrentFunctionName: () =>
speculateFunctionName({
diskSizeInMb: 10240,
memorySizeInMb: 3009,
timeoutInSeconds: 120,
}),
};
2 changes: 1 addition & 1 deletion packages/serverless/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
import type {BrowserSafeApis} from '@remotion/renderer/client';
import type {ExpensiveChunk} from './most-expensive-chunks';
import type {ChunkRetry, CloudProvider, ReceivedArtifact} from './types';
import type {EnhancedErrorInfo} from './write-lambda-error';
import type {EnhancedErrorInfo} from './write-error-to-storage';

// Needs to be in sync with renderer/src/options/delete-after.ts#L7
export const expiryDays = {
Expand Down
4 changes: 2 additions & 2 deletions packages/serverless/src/create-post-render-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {OverallRenderProgress} from './overall-render-progress';
import type {ProviderSpecifics} from './provider-implementation';
import type {RenderMetadata} from './render-metadata';
import type {CloudProvider} from './types';
import type {EnhancedErrorInfo} from './write-lambda-error';
import type {EnhancedErrorInfo} from './write-error-to-storage';

export const createPostRenderData = <Provider extends CloudProvider>({
region,
Expand Down Expand Up @@ -96,7 +96,7 @@ export const createPostRenderData = <Provider extends CloudProvider>({
? []
: getMostExpensiveChunks({
parsedTimings,
framesPerLambda: renderMetadata.framesPerLambda,
framesPerFunction: renderMetadata.framesPerLambda,
firstFrame: renderMetadata.frameRange[0],
lastFrame: renderMetadata.frameRange[1],
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/serverless/src/handlers/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {validateComposition} from '../validate-composition';
import {validateFramesPerFunction} from '../validate-frames-per-function';
import {validateOutname} from '../validate-outname';
import {validatePrivacy} from '../validate-privacy';
import {getTmpDirStateIfENoSp} from '../write-lambda-error';
import {getTmpDirStateIfENoSp} from '../write-error-to-storage';

type Options = {
expectedBucketOwner: string;
Expand Down Expand Up @@ -188,7 +188,7 @@ const innerLaunchHandler = async <Provider extends CloudProvider>({
RenderInternals.validatePuppeteerTimeout(params.timeoutInMilliseconds);

const {chunks} = planFrameRanges({
framesPerLambda,
framesPerFunction: framesPerLambda,
frameRange: realFrameRange,
everyNthFrame: params.everyNthFrame,
});
Expand Down
8 changes: 7 additions & 1 deletion packages/serverless/src/handlers/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {VERSION} from 'remotion/version';
import type {ServerlessPayload} from '../constants';
import {ServerlessRoutines} from '../constants';
import {getProgress} from '../progress';
import type {ProviderSpecifics} from '../provider-implementation';
import type {
ProviderSpecifics,
ServerProviderSpecifics,
} from '../provider-implementation';
import type {GenericRenderProgress} from '../render-progress';
import type {CloudProvider} from '../types';

Expand All @@ -11,6 +14,7 @@ type Options<Provider extends CloudProvider> = {
timeoutInMilliseconds: number;
retriesRemaining: number;
providerSpecifics: ProviderSpecifics<Provider>;
serverProviderSpecifics: ServerProviderSpecifics;
};

export const progressHandler = async <Provider extends CloudProvider>(
Expand Down Expand Up @@ -45,6 +49,7 @@ export const progressHandler = async <Provider extends CloudProvider>(
providerSpecifics: options.providerSpecifics,
forcePathStyle: lambdaParams.forcePathStyle,
functionName: process.env.AWS_LAMBDA_FUNCTION_NAME as string,
serverProviderSpecifics: options.serverProviderSpecifics,
});
return progress;
} catch (err) {
Expand All @@ -61,6 +66,7 @@ export const progressHandler = async <Provider extends CloudProvider>(
timeoutInMilliseconds: options.timeoutInMilliseconds,
retriesRemaining: options.retriesRemaining - 1,
providerSpecifics: options.providerSpecifics,
serverProviderSpecifics: options.serverProviderSpecifics,
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/serverless/src/handlers/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {OnStream} from '../streaming/streaming';
import {truthy} from '../truthy';
import type {CloudProvider, ObjectChunkTimingData} from '../types';
import {enableNodeIntrospection} from '../why-is-node-running';
import {getTmpDirStateIfENoSp} from '../write-lambda-error';
import {getTmpDirStateIfENoSp} from '../write-error-to-storage';

type Options = {
expectedBucketOwner: string;
Expand Down
23 changes: 16 additions & 7 deletions packages/serverless/src/handlers/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import type {ServerlessPayload} from '../constants';
import {ServerlessRoutines, overallProgressKey} from '../constants';
import {internalGetOrCreateBucket} from '../get-or-create-bucket';
import {makeInitialOverallRenderProgress} from '../overall-render-progress';
import type {ProviderSpecifics} from '../provider-implementation';
import type {
ProviderSpecifics,
ServerProviderSpecifics,
} from '../provider-implementation';
import type {CloudProvider} from '../types';

type Options = {
Expand All @@ -12,11 +15,17 @@ type Options = {
renderId: string;
};

export const startHandler = async <Provider extends CloudProvider>(
params: ServerlessPayload<Provider>,
options: Options,
providerSpecifics: ProviderSpecifics<Provider>,
) => {
export const startHandler = async <Provider extends CloudProvider>({
params,
options,
providerSpecifics,
serverProviderSpecifics,
}: {
params: ServerlessPayload<Provider>;
options: Options;
providerSpecifics: ProviderSpecifics<Provider>;
serverProviderSpecifics: ServerProviderSpecifics;
}) => {
if (params.type !== ServerlessRoutines.start) {
throw new TypeError('Expected type start');
}
Expand Down Expand Up @@ -118,7 +127,7 @@ export const startHandler = async <Provider extends CloudProvider>(
};

await providerSpecifics.callFunctionAsync({
functionName: providerSpecifics.getCurrentFunctionName(),
functionName: serverProviderSpecifics.getCurrentFunctionName(),
type: ServerlessRoutines.launch,
payload,
region,
Expand Down
Loading

0 comments on commit 7d74dfa

Please sign in to comment.