mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
refactor(cli): minimize studioServer.ts diff for telemetry wiring
Net diff is now +3 lines: import line and the two emit calls. Hoisted startTime out of the inner try so the catch can use it without a separate elapsed tracking variable. Pre-existing complexity findings in studioServer.ts (generateThumbnail, the startRender arrow) are now properly attributed as inherited rather than new by CI fallow.
This commit is contained in:
@@ -254,6 +254,7 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Run render asynchronously, mutating the state object
|
// Run render asynchronously, mutating the state object
|
||||||
|
const startTime = Date.now();
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const { createRenderJob, executeRenderJob } = await import("@hyperframes/producer");
|
const { createRenderJob, executeRenderJob } = await import("@hyperframes/producer");
|
||||||
@@ -280,30 +281,23 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
|||||||
...(manualEditsRenderScript ? { renderBodyScripts: [manualEditsRenderScript] } : {}),
|
...(manualEditsRenderScript ? { renderBodyScripts: [manualEditsRenderScript] } : {}),
|
||||||
...(opts.composition ? { entryFile: opts.composition } : {}),
|
...(opts.composition ? { entryFile: opts.composition } : {}),
|
||||||
});
|
});
|
||||||
const startTime = Date.now();
|
|
||||||
let lastStage: string | undefined;
|
|
||||||
const onProgress = (j: { progress: number; currentStage?: string }) => {
|
const onProgress = (j: { progress: number; currentStage?: string }) => {
|
||||||
state.progress = j.progress;
|
state.progress = j.progress;
|
||||||
if (j.currentStage) {
|
if (j.currentStage) state.stage = j.currentStage;
|
||||||
state.stage = j.currentStage;
|
|
||||||
lastStage = j.currentStage;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
try {
|
await executeRenderJob(job, opts.project.dir, opts.outputPath, onProgress);
|
||||||
await executeRenderJob(job, opts.project.dir, opts.outputPath, onProgress);
|
|
||||||
} catch (renderErr) {
|
|
||||||
emitStudioRenderError(opts, Date.now() - startTime, lastStage, renderErr);
|
|
||||||
throw renderErr;
|
|
||||||
}
|
|
||||||
const elapsed = Date.now() - startTime;
|
|
||||||
state.status = "complete";
|
state.status = "complete";
|
||||||
state.progress = 100;
|
state.progress = 100;
|
||||||
const metaPath = opts.outputPath.replace(/\.(mp4|webm|mov)$/, ".meta.json");
|
const metaPath = opts.outputPath.replace(/\.(mp4|webm|mov)$/, ".meta.json");
|
||||||
writeFileSync(metaPath, JSON.stringify({ status: "complete", durationMs: elapsed }));
|
writeFileSync(
|
||||||
emitStudioRenderComplete(opts, elapsed, job.perfSummary);
|
metaPath,
|
||||||
|
JSON.stringify({ status: "complete", durationMs: Date.now() - startTime }),
|
||||||
|
);
|
||||||
|
emitStudioRenderComplete(opts, Date.now() - startTime, job.perfSummary);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
state.status = "failed";
|
state.status = "failed";
|
||||||
state.error = err instanceof Error ? err.message : String(err);
|
state.error = err instanceof Error ? err.message : String(err);
|
||||||
|
emitStudioRenderError(opts, Date.now() - startTime, state.stage, err);
|
||||||
try {
|
try {
|
||||||
const metaPath = opts.outputPath.replace(/\.(mp4|webm|mov)$/, ".meta.json");
|
const metaPath = opts.outputPath.replace(/\.(mp4|webm|mov)$/, ".meta.json");
|
||||||
writeFileSync(metaPath, JSON.stringify({ status: "failed" }));
|
writeFileSync(metaPath, JSON.stringify({ status: "failed" }));
|
||||||
|
|||||||
Reference in New Issue
Block a user