Skip to content

Commit e4f7ce7

Browse files
authored
chore: use master for select (#1014)
1 parent 260999d commit e4f7ce7

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/modules/file/file.repository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,13 +1077,17 @@ export class SequelizeFileRepository implements FileRepository {
10771077
async findDeletedFilesUpdatedBefore(
10781078
cutoffDate: Date,
10791079
limit: number,
1080+
opts?: {
1081+
useMaster: boolean;
1082+
},
10801083
): Promise<string[]> {
10811084
const rows = await this.fileModel.findAll({
10821085
attributes: ['uuid'],
10831086
where: {
10841087
status: FileStatus.DELETED,
10851088
updatedAt: { [Op.lt]: cutoffDate },
10861089
},
1090+
useMaster: opts?.useMaster,
10871091
limit,
10881092
});
10891093

src/modules/jobs/tasks/hard-delete-old-files/hard-delete-old-files.processor.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ describe('HardDeleteOldFilesProcessor', () => {
9797
expect(fileRepository.findDeletedFilesUpdatedBefore).toHaveBeenCalledWith(
9898
expectedCutoff,
9999
BATCH_SIZE,
100+
{ useMaster: true },
100101
);
101102
});
102103

src/modules/jobs/tasks/hard-delete-old-files/hard-delete-old-files.processor.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,26 @@ export class HardDeleteOldFilesProcessor extends WorkerHost {
2424
}
2525

2626
async process(_job: Job) {
27-
const cutoffDate = Time.daysAgo(SIX_MONTHS_IN_DAYS);
27+
try {
28+
const cutoffDate = Time.daysAgo(SIX_MONTHS_IN_DAYS);
2829

29-
this.logger.log(
30-
{ cutoffDate },
31-
'Starting hard-delete of old deleted files.',
32-
);
30+
this.logger.log(
31+
{ cutoffDate },
32+
'Starting hard-delete of old deleted files.',
33+
);
3334

34-
const filesDeleted = await this.deleteInBatches(cutoffDate);
35+
const filesDeleted = await this.deleteInBatches(cutoffDate);
3536

36-
this.logger.log(
37-
{ filesDeleted },
38-
'Hard-delete of old deleted files completed.',
39-
);
37+
this.logger.log(
38+
{ filesDeleted },
39+
'Hard-delete of old deleted files completed.',
40+
);
4041

41-
return { filesDeleted };
42+
return { filesDeleted };
43+
} catch (error) {
44+
this.logger.error({ error }, 'Hard-delete of old deleted files failed.');
45+
throw error;
46+
}
4247
}
4348

4449
private async deleteInBatches(cutoffDate: Date): Promise<number> {
@@ -49,6 +54,7 @@ export class HardDeleteOldFilesProcessor extends WorkerHost {
4954
const uuids = await this.fileRepository.findDeletedFilesUpdatedBefore(
5055
cutoffDate,
5156
BATCH_SIZE,
57+
{ useMaster: true },
5258
);
5359

5460
this.logger.log({ uuids }, 'files to delete');

0 commit comments

Comments
 (0)