Skip to content

Commit

Permalink
fix: delete unfinished shares after a day
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Oct 21, 2023
1 parent 8ae631a commit d327bc3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion backend/src/jobs/jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ export class JobsService {
}
}

@Cron("0 */6 * * *")
async deleteUnfinishedShares() {
const unfinishedShares = await this.prisma.share.findMany({
where: {
createdAt: { lt: moment().subtract(1, "day").toDate() },
uploadLocked: false,
},
});

for (const unfinishedShare of unfinishedShares) {
await this.prisma.share.delete({
where: { id: unfinishedShare.id },
});

await this.fileService.deleteAllFiles(unfinishedShare.id);
}

if (unfinishedShares.length > 0) {
this.logger.log(`Deleted ${unfinishedShares.length} unfinished shares`);
}
}

@Cron("0 0 * * *")
deleteTemporaryFiles() {
let filesDeleted = 0;
Expand Down Expand Up @@ -93,7 +115,7 @@ export class JobsService {
this.logger.log(`Deleted ${filesDeleted} temporary files`);
}

@Cron("0 * * * *")
@Cron("1 * * * *")
async deleteExpiredTokens() {
const { count: refreshTokenCount } =
await this.prisma.refreshToken.deleteMany({
Expand Down

0 comments on commit d327bc3

Please sign in to comment.