0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-03-11 02:23:09 -05:00

use global library watch lock

This commit is contained in:
Jonathan Jogenfors 2024-02-29 18:50:05 +01:00
parent c07ef59167
commit eda6572c87

View file

@ -70,8 +70,16 @@ export class LibraryService extends EventEmitter {
async init() { async init() {
const config = await this.configCore.getConfig(); const config = await this.configCore.getConfig();
const { watch, scan } = config.library; const { watch, scan } = config.library;
this.watchLibraries = watch.enabled; this.watchLibraries = false;
if (watch.enabled) {
this.databaseRepository.withTryLock(DatabaseLock.LibraryWatch, async () => {
// This ensures that library watching only occurs in one microservice
// TODO: we could make the lock be per-library instead of global
this.watchLibraries = true;
});
}
this.jobRepository.addCronJob( this.jobRepository.addCronJob(
'libraryScan', 'libraryScan',
scan.cronExpression, scan.cronExpression,
@ -106,7 +114,6 @@ export class LibraryService extends EventEmitter {
return false; return false;
} }
this.databaseRepository.withTryLock(DatabaseLock.LibraryWatch, async () => {
await this.unwatch(id); await this.unwatch(id);
this.logger.log(`Starting to watch library ${library.id} with import path(s) ${library.importPaths}`); this.logger.log(`Starting to watch library ${library.id} with import path(s) ${library.importPaths}`);
@ -159,7 +166,6 @@ export class LibraryService extends EventEmitter {
// Wait for the watcher to initialize before returning // Wait for the watcher to initialize before returning
await ready$; await ready$;
});
return true; return true;
} }