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
|
||||
const startTime = Date.now();
|
||||
(async () => {
|
||||
try {
|
||||
const { createRenderJob, executeRenderJob } = await import("@hyperframes/producer");
|
||||
@@ -280,30 +281,23 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
...(manualEditsRenderScript ? { renderBodyScripts: [manualEditsRenderScript] } : {}),
|
||||
...(opts.composition ? { entryFile: opts.composition } : {}),
|
||||
});
|
||||
const startTime = Date.now();
|
||||
let lastStage: string | undefined;
|
||||
const onProgress = (j: { progress: number; currentStage?: string }) => {
|
||||
state.progress = j.progress;
|
||||
if (j.currentStage) {
|
||||
state.stage = j.currentStage;
|
||||
lastStage = j.currentStage;
|
||||
}
|
||||
if (j.currentStage) state.stage = j.currentStage;
|
||||
};
|
||||
try {
|
||||
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;
|
||||
await executeRenderJob(job, opts.project.dir, opts.outputPath, onProgress);
|
||||
state.status = "complete";
|
||||
state.progress = 100;
|
||||
const metaPath = opts.outputPath.replace(/\.(mp4|webm|mov)$/, ".meta.json");
|
||||
writeFileSync(metaPath, JSON.stringify({ status: "complete", durationMs: elapsed }));
|
||||
emitStudioRenderComplete(opts, elapsed, job.perfSummary);
|
||||
writeFileSync(
|
||||
metaPath,
|
||||
JSON.stringify({ status: "complete", durationMs: Date.now() - startTime }),
|
||||
);
|
||||
emitStudioRenderComplete(opts, Date.now() - startTime, job.perfSummary);
|
||||
} catch (err) {
|
||||
state.status = "failed";
|
||||
state.error = err instanceof Error ? err.message : String(err);
|
||||
emitStudioRenderError(opts, Date.now() - startTime, state.stage, err);
|
||||
try {
|
||||
const metaPath = opts.outputPath.replace(/\.(mp4|webm|mov)$/, ".meta.json");
|
||||
writeFileSync(metaPath, JSON.stringify({ status: "failed" }));
|
||||
|
||||
Reference in New Issue
Block a user