feat(watcher): polling desteği ekle

CORE_WATCHER_USE_POLLING ve CORE_WATCHER_POLL_INTERVAL_MS ortam
değişkenleri eklendi. Bu değişkenler sayesinde dosya izleyici için
polling modu ve aralığı yapılandırılabilir hale getirildi.
This commit is contained in:
2026-02-16 14:47:26 +03:00
parent 02e413c17a
commit 14c64d8032
3 changed files with 14 additions and 2 deletions

View File

@@ -13,6 +13,8 @@ MEDIA_MOVIE_PATH=/media/movie
ENABLE_API_KEY=false
API_KEY=
CORE_WATCHER_DEDUP_WINDOW_MS=15000
CORE_WATCHER_USE_POLLING=false
CORE_WATCHER_POLL_INTERVAL_MS=2000
ENABLE_TA_STEP_LOGS=false
CLAMAV_AUTO_UPDATE=true
CLAMAV_FAIL_ON_UPDATE_ERROR=false

View File

@@ -15,5 +15,7 @@ export const env = {
enableApiKey: process.env.ENABLE_API_KEY === 'true',
apiKey: process.env.API_KEY ?? '',
watcherDedupWindowMs: Number(process.env.CORE_WATCHER_DEDUP_WINDOW_MS ?? 15000),
watcherUsePolling: process.env.CORE_WATCHER_USE_POLLING === 'true',
watcherPollIntervalMs: Number(process.env.CORE_WATCHER_POLL_INTERVAL_MS ?? 2000),
isDev: (process.env.NODE_ENV ?? 'development') !== 'production'
};

View File

@@ -26,7 +26,13 @@ export async function startWatcher(): Promise<void> {
const byPath = new Map(watched.map((w) => [w.path, w.kind]));
const shouldProcessEvent = createEventDeduper(env.watcherDedupWindowMs);
const watcher = chokidar.watch(paths, { ignoreInitial: false, awaitWriteFinish: false, persistent: true });
const watcher = chokidar.watch(paths, {
ignoreInitial: false,
awaitWriteFinish: false,
persistent: true,
usePolling: env.watcherUsePolling,
interval: env.watcherPollIntervalMs
});
watcher.on('add', async (p) => {
if (!isVideoFile(p)) return;
@@ -51,7 +57,9 @@ export async function startWatcher(): Promise<void> {
await media.MediaFileModel.updateOne({ path: p }, { status: 'MISSING', lastSeenAt: new Date() });
});
console.log(`[core] watcher started for: ${paths.join(', ')}`);
console.log(
`[core] watcher started for: ${paths.join(', ')} (polling=${env.watcherUsePolling ? 'on' : 'off'}, intervalMs=${env.watcherPollIntervalMs})`
);
}
function resolveKind(filePath: string, byPath: Map<string, 'tv' | 'movie' | 'mixed'>): 'tv' | 'movie' {