mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-04 21:17:30 +00:00
* fix(cli): check stops making video copies after 10 minutes, and --timeout takes units The copy phase of check had no overall limit: a source that kept moving was never stopped, and stdout stays silent the whole time. It now ends after 10 minutes with an error naming the files still unfinished and the elapsed seconds; finished copies are reused on the next run. The stderr progress lines are unchanged. --timeout on check and snapshot is milliseconds, so "--timeout 45" waited 45 ms. It now accepts 45s, 2m and 45000ms, and a bare number under 1000 warns on stderr that it is milliseconds. Output on stdout is unchanged. * chore(cli): cut the --timeout parser comment to the comment limit * fix(cli): drop the 10 minute wall clock on check's video copies A copy that keeps making progress must not be cut by a clock, and a re-run would only start it over. The copy already ends when ffmpeg stops reporting progress for 3 minutes (finished pieces are kept for the next run), so the phase is bounded on no progress. The --timeout warning now names the value actually used when check raises a small value to its 500 ms floor.
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
const UNIT_MS = { ms: 1, s: 1_000, m: 60_000 } as const;
|
|
|
|
/** Reads a `--timeout` as milliseconds, raised to `floorMs`; `45s`, `2m` and `45000ms` carry a unit.
|
|
* A bare value under 1000 is kept but warned about: it is usually seconds. */
|
|
export function parseTimeoutMs(
|
|
raw: unknown,
|
|
fallback: number,
|
|
floorMs = 0,
|
|
warn: (message: string) => void = console.error,
|
|
): number {
|
|
if (raw === undefined || raw === null || raw === "") return fallback;
|
|
const text = String(raw).trim();
|
|
const match = /^(\d+(?:\.\d+)?)\s*(ms|s|m)?$/i.exec(text);
|
|
if (!match) {
|
|
warn(`[hyperframes] --timeout "${text}" is not a duration; using ${fallback} ms.`);
|
|
return fallback;
|
|
}
|
|
const unit = match[2]?.toLowerCase() as keyof typeof UNIT_MS | undefined;
|
|
const ms = Math.round(Number(match[1]) * UNIT_MS[unit ?? "ms"]);
|
|
if (ms <= 0) return fallback;
|
|
const used = Math.max(ms, floorMs);
|
|
if (!unit && ms < 1_000) {
|
|
warn(
|
|
`[hyperframes] --timeout ${text} is ${ms} ms, so ${used} ms is used. Write ${text}s for seconds.`,
|
|
);
|
|
}
|
|
return used;
|
|
}
|