Skip to content

Commit

Permalink
fix: library scanning cron job created on every instance instead of j…
Browse files Browse the repository at this point in the history
…ust one
  • Loading branch information
zackpollard committed Oct 25, 2024
1 parent c124cf9 commit fa7dfc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 9 additions & 0 deletions server/src/services/library.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ describe(LibraryService.name, () => {

expect(storageMock.watch).not.toHaveBeenCalled();
});

it('should not initialize library scan cron job when lock is taken', async () => {
systemMock.get.mockResolvedValue(systemConfigStub.libraryWatchEnabled);
databaseMock.tryLock.mockResolvedValue(false);

await sut.onBootstrap();

expect(jobMock.addCronJob).not.toHaveBeenCalled();
});
});

describe('onConfigUpdateEvent', () => {
Expand Down
14 changes: 8 additions & 6 deletions server/src/services/library.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ export class LibraryService extends BaseService {

this.watchLibraries = this.watchLock && watch.enabled;

this.jobRepository.addCronJob(
'libraryScan',
scan.cronExpression,
() => handlePromiseError(this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SYNC_ALL }), this.logger),
scan.enabled,
);
if (this.watchLock) {
this.jobRepository.addCronJob(
'libraryScan',
scan.cronExpression,
() => handlePromiseError(this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SYNC_ALL }), this.logger),
scan.enabled,
);
}

if (this.watchLibraries) {
await this.watchAll();
Expand Down

0 comments on commit fa7dfc0

Please sign in to comment.