fix: close competition cutover integrity gaps

This commit is contained in:
dahyeon committed 2026-07-12 21:22:22 +00:00
1 parent 7ea2002975
commit 683d602d63
57 files changed
+4805 -1582

No files matched your search

@@ -1,4 +1,9 @@
import { Injectable, Logger, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import {
Injectable,
Logger,
OnModuleDestroy,
OnModuleInit,
} from '@nestjs/common';
import { DistributedLockService } from '../global/redis/distributed-lock.service';
import { TournamentResultService } from '../tournament-result/tournament-result.service';
import { TournamentCodeAutoProvisionService } from './tournament-code-auto-provision.service';
@@ -31,13 +36,19 @@ export class TournamentCodeScheduler implements OnModuleInit, OnModuleDestroy {
this.attachTimer = setInterval(() => {
void this.attachPending();
}, 30_000);
this.expireTimer = setInterval(() => {
void this.markExpired();
}, 60 * 60 * 1000);
this.expireTimer = setInterval(
() => {
void this.markExpired();
},
60 * 60 * 1000,
);
if (isAutoProvisionEnabled()) {
this.refillTimer = setInterval(() => {
void this.ensureVendorPool();
}, 5 * 60 * 1000);
this.refillTimer = setInterval(
() => {
void this.ensureVendorPool();
},
5 * 60 * 1000,
);
}
this.attachTimer.unref?.();
this.expireTimer.unref?.();
@@ -99,7 +110,18 @@ export class TournamentCodeScheduler implements OnModuleInit, OnModuleDestroy {
SCHEDULER_LOCK_RENEWAL_INTERVAL_MILLISECONDS,
},
async () => {
await this.tournamentCodeService.markExpired();
const result = await this.tournamentCodeService.markExpired();
for (const matchId of result.affectedMatchIds) {
try {
await this.tournamentResultService.scheduleInitialPoll(matchId);
} catch (error) {
this.logger.warn(
`Failed to reconcile Competition codes after expiring a code for Match ${matchId.toString()}: ${
error instanceof Error ? error.message : error
}`,
);
}
}
},
);
} catch (error) {
@@ -136,8 +158,7 @@ export class TournamentCodeScheduler implements OnModuleInit, OnModuleDestroy {
}
function isAutoProvisionEnabled(): boolean {
const raw = process.env.TOURNAMENT_CODE_AUTO_PROVISION_ENABLED
?.trim()
.toLowerCase();
const raw =
process.env.TOURNAMENT_CODE_AUTO_PROVISION_ENABLED?.trim().toLowerCase();
return raw !== 'false' && raw !== '0' && raw !== 'off';
}