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 access: AccessCore;
|
||||||
private configCore: SystemConfigCore;
|
private configCore: SystemConfigCore;
|
||||||
private watchLibraries = false;
|
private watchLibraries = false;
|
||||||
|
private watchLock = false;
|
||||||
private watchers: Record<string, () => void> = {};
|
private watchers: Record<string, () => void> = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -73,11 +74,13 @@ export class LibraryService extends EventEmitter {
|
||||||
const config = await this.configCore.getConfig();
|
const config = await this.configCore.getConfig();
|
||||||
|
|
||||||
const { watch, scan } = config.library;
|
const { watch, scan } = config.library;
|
||||||
this.watchLibraries = false;
|
|
||||||
if (watch.enabled) {
|
if (watch.enabled) {
|
||||||
// This ensures that library watching only occurs in one microservice
|
// This ensures that library watching only occurs in one microservice
|
||||||
// TODO: we could make the lock be per-library instead of global
|
// 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(
|
this.jobRepository.addCronJob(
|
||||||
'libraryScan',
|
'libraryScan',
|
||||||
|
@ -93,7 +96,7 @@ export class LibraryService extends EventEmitter {
|
||||||
this.configCore.config$.subscribe(async ({ library }) => {
|
this.configCore.config$.subscribe(async ({ library }) => {
|
||||||
this.jobRepository.updateCronJob('libraryScan', library.scan.cronExpression, library.scan.enabled);
|
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;
|
this.watchLibraries = library.watch.enabled;
|
||||||
await (this.watchLibraries ? this.watchAll() : this.unwatchAll());
|
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> {
|
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> {
|
private async releaseLock(lock: DatabaseLock, queryRunner: QueryRunner): Promise<void> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue