mirror of
https://github.com/immich-app/immich.git
synced 2025-03-11 02:23:09 -05:00
fix: correct return type of try lock
This commit is contained in:
parent
e7f2c25a1d
commit
1764f8cf15
2 changed files with 8 additions and 4 deletions
|
@ -45,6 +45,7 @@ export class LibraryService extends EventEmitter {
|
|||
private access: AccessCore;
|
||||
private configCore: SystemConfigCore;
|
||||
private watchLibraries = false;
|
||||
private watchLock = false;
|
||||
private watchers: Record<string, () => void> = {};
|
||||
|
||||
constructor(
|
||||
|
@ -73,11 +74,13 @@ export class LibraryService extends EventEmitter {
|
|||
const config = await this.configCore.getConfig();
|
||||
|
||||
const { watch, scan } = config.library;
|
||||
this.watchLibraries = false;
|
||||
|
||||
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.watchLibraries = await this.databaseRepository.tryLock(DatabaseLock.LibraryWatch);
|
||||
|
||||
this.watchLock = await this.databaseRepository.tryLock(DatabaseLock.LibraryWatch);
|
||||
this.watchLibraries = this.watchLock;
|
||||
}
|
||||
this.jobRepository.addCronJob(
|
||||
'libraryScan',
|
||||
|
@ -93,7 +96,7 @@ export class LibraryService extends EventEmitter {
|
|||
this.configCore.config$.subscribe(async ({ library }) => {
|
||||
this.jobRepository.updateCronJob('libraryScan', library.scan.cronExpression, library.scan.enabled);
|
||||
|
||||
if (library.watch.enabled !== this.watchLibraries) {
|
||||
if (this.watchLock && library.watch.enabled !== this.watchLibraries) {
|
||||
this.watchLibraries = library.watch.enabled;
|
||||
await (this.watchLibraries ? this.watchAll() : this.unwatchAll());
|
||||
}
|
||||
|
|
|
@ -228,7 +228,8 @@ export class DatabaseRepository implements IDatabaseRepository {
|
|||
}
|
||||
|
||||
private async acquireTryLock(lock: DatabaseLock, queryRunner: QueryRunner): Promise<boolean> {
|
||||
return queryRunner.query('SELECT pg_try_advisory_lock($1)', [lock]);
|
||||
const lockResult = await queryRunner.query('SELECT pg_try_advisory_lock($1)', [lock]);
|
||||
return lockResult[0].pg_try_advisory_lock;
|
||||
}
|
||||
|
||||
private async releaseLock(lock: DatabaseLock, queryRunner: QueryRunner): Promise<void> {
|
||||
|
|
Loading…
Add table
Reference in a new issue