1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-07-02 07:20:38 +02:00

fix: only log jobs if they actually did something

This commit is contained in:
Elias Schneider 2022-10-31 10:33:27 +01:00
parent 46d667776f
commit e40cc0f48b

View File

@ -1,8 +1,8 @@
import { Injectable } from "@nestjs/common"; import { Injectable } from "@nestjs/common";
import { Cron } from "@nestjs/schedule"; import { Cron } from "@nestjs/schedule";
import * as moment from "moment";
import { FileService } from "src/file/file.service"; import { FileService } from "src/file/file.service";
import { PrismaService } from "src/prisma/prisma.service"; import { PrismaService } from "src/prisma/prisma.service";
import * as moment from "moment";
@Injectable() @Injectable()
export class JobsService { export class JobsService {
@ -31,14 +31,19 @@ export class JobsService {
await this.fileService.deleteAllFiles(expiredShare.id); await this.fileService.deleteAllFiles(expiredShare.id);
} }
console.log(`job: deleted ${expiredShares.length} expired shares`); if (expiredShares.length > 0)
console.log(`job: deleted ${expiredShares.length} expired shares`);
} }
@Cron("0 * * * *") @Cron("0 * * * *")
async deleteExpiredRefreshTokens() { async deleteExpiredRefreshTokens() {
const expiredShares = await this.prisma.refreshToken.deleteMany({ const expiredRefreshTokens = await this.prisma.refreshToken.deleteMany({
where: { expiresAt: { lt: new Date() } }, where: { expiresAt: { lt: new Date() } },
}); });
console.log(`job: deleted ${expiredShares.count} expired refresh tokens`);
if (expiredRefreshTokens.count > 0)
console.log(
`job: deleted ${expiredRefreshTokens.count} expired refresh tokens`
);
} }
} }