add library teardown

This commit is contained in:
Jonathan Jogenfors
2024-02-29 22:50:06 +01:00
parent bd4c03067b
commit 735747c939
8 changed files with 25 additions and 11 deletions
+10 -2
View File
@@ -78,8 +78,8 @@ export class LibraryService extends EventEmitter {
if (watch.enabled) {
// This ensures that library watching only occurs in one microservice
// TODO: we could make the lock be per-library instead of global
this.watchLock = await this.databaseRepository.tryLock(DatabaseLock.LibraryWatch);
this.watchLibraries = this.watchLock;
}
this.jobRepository.addCronJob(
@@ -179,7 +179,15 @@ export class LibraryService extends EventEmitter {
}
}
async unwatchAll() {
async teardown() {
await this.unwatchAll();
if (this.watchLock) {
await this.databaseRepository.releaseLock(DatabaseLock.LibraryWatch);
}
}
private async unwatchAll() {
for (const id in this.watchers) {
await this.unwatch(id);
}