music indexer: 3s progress heartbeat log during a build
A long full rebuild logged only "resync started" then nothing until "done". Add a console heartbeat (throttled to 3s, piggybacked on emitProgress) showing folders/built/skipped/tracks/videos/posters/lyrics counts + the current path, so progress is visible in the pm2 logs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -202,6 +202,7 @@ export function buildReport(s: IndexStatus = status): IndexReport {
|
||||
type ProgressListener = (s: IndexStatus) => void;
|
||||
const listeners = new Set<ProgressListener>();
|
||||
let lastEmit = 0;
|
||||
let lastLog = 0;
|
||||
|
||||
export function onIndexProgress(cb: ProgressListener): () => void {
|
||||
listeners.add(cb);
|
||||
@@ -211,6 +212,15 @@ export function onIndexProgress(cb: ProgressListener): () => void {
|
||||
/** Notify subscribers of progress; throttled to ~200ms unless `force` (e.g. terminal 'done'). */
|
||||
function emitProgress(force = false): void {
|
||||
const now = Date.now();
|
||||
// Console heartbeat (throttled to 3s, independent of the SSE cadence) so a long build shows life.
|
||||
if (now - lastLog >= 3000) {
|
||||
lastLog = now;
|
||||
console.log(
|
||||
`[music] … ${status.foldersScanned} folders · ${status.albumsBuilt} built/${status.albumsSkipped} skipped · ` +
|
||||
`${status.tracksIndexed} tracks · ${status.videosIndexed} videos · ${status.postersSaved} posters · ` +
|
||||
`${status.lyricsIndexed} lyrics — ${status.currentPath}`,
|
||||
);
|
||||
}
|
||||
if (!force && now - lastEmit < 200) return;
|
||||
lastEmit = now;
|
||||
const snap = getIndexStatus();
|
||||
|
||||
Reference in New Issue
Block a user