use global library watch lock

This commit is contained in:
Jonathan Jogenfors
2024-02-29 18:50:05 +01:00
parent c07ef59167
commit eda6572c87
+9 -3
View File
@@ -70,8 +70,16 @@ export class LibraryService extends EventEmitter {
async init() {
const config = await this.configCore.getConfig();
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(
'libraryScan',
scan.cronExpression,
@@ -106,7 +114,6 @@ export class LibraryService extends EventEmitter {
return false;
}
this.databaseRepository.withTryLock(DatabaseLock.LibraryWatch, async () => {
await this.unwatch(id);
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
await ready$;
});
return true;
}