Skip to content

🎥 Make videos programmatically with React

`@remotion/lambda`: Better diagnostics for streaming

Jonny Burger1576caed5d5c
diff --git a/packages/lambda/src/functions/index.ts b/packages/lambda/src/functions/index.ts
index aac4e76655..0923b3e130 100644
--- a/packages/lambda/src/functions/index.ts
+++ b/packages/lambda/src/functions/index.ts
@@ -202,9 +202,10 @@ const innerHandler = async ({
message: payload,
});
+ const writeProm = responseWriter.write(message);
+
return new Promise((innerResolve, innerReject) => {
- responseWriter
- .write(message)
+ writeProm
.then(() => {
innerResolve();
})
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index 1f0a1e512b..b4b043dcea 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -432,14 +432,6 @@ export const launchHandler = async (
'Function is about to time out. Can not finish render.',
);
- if (!params.webhook) {
- return;
- }
-
- if (webhookInvoked) {
- return;
- }
-
Promise.all(cleanupTasks)
.then(() => {
RenderInternals.Log.info(
@@ -455,6 +447,28 @@ export const launchHandler = async (
);
});
+ if (!params.webhook) {
+ RenderInternals.Log.verbose(
+ {
+ indent: false,
+ logLevel: params.logLevel,
+ },
+ 'No webhook specified.',
+ );
+ return;
+ }
+
+ if (webhookInvoked) {
+ RenderInternals.Log.verbose(
+ {
+ indent: false,
+ logLevel: params.logLevel,
+ },
+ 'Webhook already invoked. Not invoking again.',
+ );
+ return;
+ }
+
try {
await invokeWebhook(
{
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 9d393420f0..8e15291dfa 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -294,19 +294,49 @@ const renderHandler = async ({
);
if (audioOutputLocation) {
+ const audioChunkTimer = timer('Sending audio chunk', params.logLevel);
onStream({
type: 'audio-chunk-rendered',
payload: fs.readFileSync(audioOutputLocation),
- });
+ })
+ .then(() => {
+ audioChunkTimer.end();
+ })
+ .catch((err) => {
+ RenderInternals.Log.error(
+ {indent: false, logLevel: params.logLevel},
+ `Error occurred while streaming audio chunk to main function`,
+ );
+ RenderInternals.Log.error(
+ {indent: false, logLevel: params.logLevel},
+ err,
+ );
+ throw err;
+ });
}
if (videoOutputLocation) {
+ const videoChunkTimer = timer('Sending main chunk', params.logLevel);
onStream({
type: RenderInternals.isAudioCodec(params.codec)
? 'audio-chunk-rendered'
: 'video-chunk-rendered',
payload: fs.readFileSync(videoOutputLocation),
- });
+ })
+ .then(() => {
+ videoChunkTimer.end();
+ })
+ .catch((err) => {
+ RenderInternals.Log.error(
+ {indent: false, logLevel: params.logLevel},
+ `Error occurred while streaming main chunk to main function`,
+ );
+ RenderInternals.Log.error(
+ {indent: false, logLevel: params.logLevel},
+ err,
+ );
+ throw err;
+ });
}
const endRendered = Date.now();
@@ -321,12 +351,6 @@ const renderHandler = async ({
streamTimer.end();
});
- const writeStart = Date.now();
-
- RenderInternals.Log.verbose(
- {indent: false, logLevel: params.logLevel},
- `Streamed chunk to main function (${Date.now() - writeStart}ms)`,
- );
RenderInternals.Log.verbose(
{indent: false, logLevel: params.logLevel},
'Cleaning up and writing timings',