This commit is contained in:
legop3
2026-04-28 02:43:41 -04:00
parent ae24793057
commit 16ae430090
+31 -10
View File
@@ -604,7 +604,7 @@ async function buildReplayVideo({ sources = [] } = {}) {
function getReplayHealthSnapshot() { function getReplayHealthSnapshot() {
const now = Date.now(); const now = Date.now();
const neededWindowMs = BUILD_DURATION_MS; const neededCount = Math.max(1, Math.ceil(BUILD_DURATION_MS / 1000));
const sources = []; const sources = [];
let readyCount = 0; let readyCount = 0;
@@ -617,20 +617,41 @@ function getReplayHealthSnapshot() {
} }
for (const source of replaySources) { for (const source of replaySources) {
const entries = getVideoEntriesForSource({ id: source.id }); const key = sourceKey({ sourceType: source.type, kind: 'video', id: String(source.id) });
const inWindow = entries.filter((entry) => now - entry.endMs <= BUFFER_SECONDS * 1000); const dir = sourceDirForKey(key);
const newest = inWindow[inWindow.length - 1] || null; let recentCount = 0;
const oldest = inWindow[0] || null; let lastSegmentAt = null;
const coveredMs = newest && oldest ? Math.max(0, newest.endMs - oldest.startMs) : 0; try {
const ready = coveredMs >= neededWindowMs; const files = fs.readdirSync(dir);
for (const name of files) {
if (!/^seg-\d{6}\.mp4$/.test(name)) continue;
const full = path.join(dir, name);
let stat;
try {
stat = fs.statSync(full);
} catch {
continue;
}
if (!stat.isFile() || stat.size < 4096) continue;
if (stat.mtimeMs > (lastSegmentAt || 0)) {
lastSegmentAt = stat.mtimeMs;
}
if (now - stat.mtimeMs <= BUFFER_SECONDS * 1000) {
recentCount += 1;
}
}
} catch {
// ignore missing source directory
}
const ready = recentCount >= neededCount;
if (ready) readyCount += 1; if (ready) readyCount += 1;
sources.push({ sources.push({
type: source.type, type: source.type,
id: source.id, id: source.id,
label: source.label, label: source.label,
recentCount: inWindow.length, recentCount,
neededCount: Math.ceil(neededWindowMs / 1000), neededCount,
lastSegmentAt: newest?.endMs || null, lastSegmentAt,
ready, ready,
}); });
} }