refactor: config init event for first config load (#13930)

This commit is contained in:
Zack Pollard 2024-11-05 16:30:56 +00:00 committed by GitHub
parent c383e115af
commit d456d35510
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 160 additions and 146 deletions

View file

@ -14,14 +14,15 @@ import { validateCronExpression } from 'src/validation';
export class BackupService extends BaseService {
private backupLock = false;
@OnEvent({ name: 'app.bootstrap' })
async onBootstrap(workerType: ImmichWorker) {
if (workerType !== ImmichWorker.API) {
@OnEvent({ name: 'config.init' })
async onConfigInit({
newConfig: {
backup: { database },
},
}: ArgOf<'config.init'>) {
if (this.worker !== ImmichWorker.API) {
return;
}
const {
backup: { database },
} = await this.getConfig({ withCache: true });
this.backupLock = await this.databaseRepository.tryLock(DatabaseLock.BackupDatabase);
@ -36,8 +37,8 @@ export class BackupService extends BaseService {
}
@OnEvent({ name: 'config.update', server: true })
onConfigUpdate({ newConfig: { backup }, oldConfig }: ArgOf<'config.update'>) {
if (!oldConfig || !this.backupLock) {
onConfigUpdate({ newConfig: { backup } }: ArgOf<'config.update'>) {
if (!this.backupLock) {
return;
}