feat: run Riot background refresh by default

This commit is contained in:
dahyeon committed 2026-06-07 09:51:51 -07:00
1 parent 528744ebf6
commit 1c0af891fa
3 files changed
+8 -25

No files matched your search

+2 -2
View File
@@ -27,8 +27,8 @@
## Riot Background Refresh
Set `RIOT_BG_REFRESH_ENABLED=true` to refresh stale Riot accounts automatically
between KST 03:00 and 10:00. The scheduler picks active users whose
Stale Riot accounts refresh automatically between KST 03:00 and 10:00.
The scheduler picks active users whose
`lastRefreshRequestedAt` is older than 6 hours, oldest first, and uses a
background-only Riot token bucket capped at roughly 40% of the app rate limit.
@@ -1,4 +1,3 @@
import { ConfigService } from '@nestjs/config';
import mongoose from 'mongoose';
import { GarnetService } from '../global/garnet/garnet.service';
import { RiotAccountEnrichmentService } from '../riot/riot-account-enrichment.service';
@@ -30,7 +29,7 @@ function candidate(puuid: string): StaleAccountCandidate {
};
}
function makeScheduler(enabled = true) {
function makeScheduler() {
const rawClient = {
sendCommand: jest.fn().mockResolvedValue(1),
};
@@ -51,16 +50,11 @@ function makeScheduler(enabled = true) {
const staleAccountRepository = {
findStaleAccounts: jest.fn().mockResolvedValue([]),
} as unknown as jest.Mocked<StaleAccountRepository>;
const config = {
get: jest.fn().mockReturnValue(enabled ? 'true' : 'false'),
} as unknown as ConfigService;
const scheduler = new BackgroundRefreshScheduler(
garnet,
rateLimiter,
enrichmentService,
staleAccountRepository,
config,
) as SchedulerInternals;
return {
@@ -79,14 +73,15 @@ describe('BackgroundRefreshScheduler', () => {
jest.restoreAllMocks();
});
it('does not schedule ticks when disabled', () => {
it('schedules ticks without requiring RIOT_BG_REFRESH_ENABLED', () => {
jest.useFakeTimers();
const setIntervalSpy = jest.spyOn(global, 'setInterval');
const { scheduler } = makeScheduler(false);
const { scheduler } = makeScheduler();
scheduler.onModuleInit();
expect(setIntervalSpy).not.toHaveBeenCalled();
expect(setIntervalSpy).toHaveBeenCalledTimes(2);
scheduler.onModuleDestroy();
});
it('does not query stale accounts outside the KST window', async () => {
@@ -4,7 +4,6 @@ import {
OnModuleDestroy,
OnModuleInit,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
type EnrichResult,
RiotAccountEnrichmentService,
@@ -34,26 +33,15 @@ export class BackgroundRefreshScheduler
private leaderRenewTimer?: NodeJS.Timeout;
private tickInProgress = false;
private readonly consumer = `${process.pid}:${Math.random().toString(36).slice(2)}`;
private readonly enabled: boolean;
constructor(
private readonly garnet: GarnetService,
private readonly rateLimiter: RiotRateLimiterService,
private readonly enrichmentService: RiotAccountEnrichmentService,
private readonly staleAccountRepository: StaleAccountRepository,
config: ConfigService,
) {
this.enabled = config.get<string>('RIOT_BG_REFRESH_ENABLED') === 'true';
}
) {}
public onModuleInit(): void {
if (!this.enabled) {
this.logger.log(
'Background Riot refresh is disabled (RIOT_BG_REFRESH_ENABLED).',
);
return;
}
this.tickTimer = setInterval(() => void this.safeTick(), TICK_INTERVAL_MS);
this.leaderRenewTimer = setInterval(
() => void this.renewLeaderIfHeld(),