This commit is contained in:
2026-04-16 17:21:48 +03:00
parent c8fa4c442d
commit c8e7e4e927
116 changed files with 3720 additions and 4197 deletions
+17 -17
View File
@@ -1,6 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { PrismaService } from '../database/prisma.service';
import { Injectable, Logger } from "@nestjs/common";
import { Cron } from "@nestjs/schedule";
import { PrismaService } from "../database/prisma.service";
@Injectable()
export class LimitResetterTask {
@@ -9,7 +9,7 @@ export class LimitResetterTask {
constructor(private readonly prisma: PrismaService) {}
private shouldSkipInHistoricalMode(jobName: string): boolean {
if (process.env.FEEDER_MODE === 'historical') {
if (process.env.FEEDER_MODE === "historical") {
this.logger.debug(`Skipping ${jobName} in historical feeder mode`);
return true;
}
@@ -19,10 +19,10 @@ export class LimitResetterTask {
/**
* Reset usage limits daily at 03:00 (Europe/Istanbul)
*/
@Cron('0 3 * * *', { timeZone: 'Europe/Istanbul' })
@Cron("0 3 * * *", { timeZone: "Europe/Istanbul" })
async resetUsageLimits() {
if (this.shouldSkipInHistoricalMode('resetUsageLimits')) return;
this.logger.log('Starting daily usage limit reset job...');
if (this.shouldSkipInHistoricalMode("resetUsageLimits")) return;
this.logger.log("Starting daily usage limit reset job...");
try {
const today = new Date();
@@ -45,7 +45,7 @@ export class LimitResetterTask {
`Usage limits for ${result.count} users have been reset`,
);
} else {
this.logger.log('No user limits needed resetting');
this.logger.log("No user limits needed resetting");
}
} catch (error: any) {
this.logger.error(`Limit reset job failed: ${error.message}`);
@@ -55,10 +55,10 @@ export class LimitResetterTask {
/**
* Clean up old predictions (older than 30 days)
*/
@Cron('0 4 * * *', { timeZone: 'Europe/Istanbul' })
@Cron("0 4 * * *", { timeZone: "Europe/Istanbul" })
async cleanupOldData() {
if (this.shouldSkipInHistoricalMode('cleanupOldData')) return;
this.logger.log('Starting data cleanup job...');
if (this.shouldSkipInHistoricalMode("cleanupOldData")) return;
this.logger.log("Starting data cleanup job...");
try {
const thirtyDaysAgo = new Date();
@@ -78,7 +78,7 @@ export class LimitResetterTask {
const deletedLiveMatches = await this.prisma.liveMatch.deleteMany({
where: {
state: 'Finished',
state: "Finished",
updatedAt: { lt: oneDayAgo },
},
});
@@ -94,21 +94,21 @@ export class LimitResetterTask {
/**
* Reset subscription status for expired users
*/
@Cron('0 0 * * *', { timeZone: 'Europe/Istanbul' })
@Cron("0 0 * * *", { timeZone: "Europe/Istanbul" })
async checkSubscriptions() {
if (this.shouldSkipInHistoricalMode('checkSubscriptions')) return;
this.logger.log('Checking expired subscriptions...');
if (this.shouldSkipInHistoricalMode("checkSubscriptions")) return;
this.logger.log("Checking expired subscriptions...");
try {
const now = new Date();
const result = await this.prisma.user.updateMany({
where: {
subscriptionStatus: 'active',
subscriptionStatus: "active",
subscriptionExpiresAt: { lt: now },
},
data: {
subscriptionStatus: 'expired',
subscriptionStatus: "expired",
},
});