refactor(v024): TelemetryService DAY_MS 상수 + media.gc .catch (backlog #2 #6)

- #2: 24*60*60*1000 magic number → 모듈 상단 const DAY_MS
  cleanupOldFiles + readAllRecent 두 callsite 통일
- #6: gc.run() 의 .catch 누락 → backup.runDaily 패턴 통일
  실패 시 logger.warn('media.gc.failed', { reason })

Note: backlog #1 (now() 2번 호출) 은 PR #13 round 1 review 시 이미 fix —
backlog 항목 stale. v0.2.5 brainstorm 시 backlog 정리.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
altair823
2026-05-05 00:11:38 +09:00
parent 4bde148cdc
commit ef5d3daf4c
2 changed files with 6 additions and 3 deletions

View File

@@ -146,7 +146,9 @@ app.whenReady().then(async () => {
await worker.loadFromDb();
const gc = new MediaGc(db, store);
void gc.run().then((r) => logger.info('media.gc', { ...r } as Record<string, unknown>));
void gc.run()
.then((r) => logger.info('media.gc', { ...r } as Record<string, unknown>))
.catch((e) => logger.warn('media.gc.failed', { reason: String(e) }));
const exportSvc = new ExportService(repo, store);
const importSvc = new ImportService(repo, store);

View File

@@ -4,6 +4,7 @@ import { validateEvent, TelemetryEvent } from './telemetryEvents.js';
import { aggregateStats } from './telemetryStats.js';
const KST_OFFSET_MS = 9 * 60 * 60 * 1000;
const DAY_MS = 24 * 60 * 60 * 1000;
function todayKstIso(now: Date): string {
const k = new Date(now.getTime() + KST_OFFSET_MS);
@@ -52,7 +53,7 @@ export class TelemetryService {
} catch {
return { removed };
}
const cutoff = new Date(this.now().getTime() - this.retentionDays * 24 * 60 * 60 * 1000);
const cutoff = new Date(this.now().getTime() - this.retentionDays * DAY_MS);
const cutoffIso = todayKstIso(cutoff); // KST 일자 비교
for (const name of entries) {
const m = /^events-(\d{4}-\d{2}-\d{2})\.jsonl$/.exec(name);
@@ -94,7 +95,7 @@ export class TelemetryService {
} catch {
return events;
}
const cutoffMs = this.now().getTime() - this.retentionDays * 24 * 60 * 60 * 1000;
const cutoffMs = this.now().getTime() - this.retentionDays * DAY_MS;
const cutoffIso = todayKstIso(new Date(cutoffMs));
// 회차 1 review (PR #13) — 매직 슬라이스 `n.slice(7, 17)` 대신 정규식 capture 그룹으로
// 일자를 추출. prefix 변경 시 정규식 한 곳만 고치면 됨.