diff --git a/src/matches/match-assistant/match-assistant.service.ts b/src/matches/match-assistant/match-assistant.service.ts index 83df1baa..0043b3e4 100644 --- a/src/matches/match-assistant/match-assistant.service.ts +++ b/src/matches/match-assistant/match-assistant.service.ts @@ -255,6 +255,13 @@ export class MatchAssistantService { error, ); if (error instanceof FailedToCreateOnDemandServer) { + if (tries >= 10) { + this.logger.error( + `[${matchId}] max retries reached for server assignment`, + ); + await this.updateMatchStatus(matchId, "WaitingForServer"); + return; + } setTimeout(async () => { this.logger.log(`[${matchId}] try retry assign server....`); await this.assignServer(matchId, ++tries); diff --git a/src/redis/redis-manager/redis-manager.service.ts b/src/redis/redis-manager/redis-manager.service.ts index fd08b542..16b0d882 100644 --- a/src/redis/redis-manager/redis-manager.service.ts +++ b/src/redis/redis-manager/redis-manager.service.ts @@ -1,10 +1,10 @@ -import { Injectable, Logger } from "@nestjs/common"; +import { Injectable, Logger, OnApplicationShutdown } from "@nestjs/common"; import IORedis, { Redis, RedisOptions } from "ioredis"; import { ConfigService } from "@nestjs/config"; import { RedisConfig } from "../../configs/types/RedisConfig"; @Injectable() -export class RedisManagerService { +export class RedisManagerService implements OnApplicationShutdown { private config: RedisConfig; protected connections: { @@ -22,6 +22,15 @@ export class RedisManagerService { this.config = this.configService.get("redis"); } + onApplicationShutdown() { + for (const [, interval] of Object.entries(this.healthCheckIntervals)) { + clearInterval(interval); + } + for (const [, conn] of Object.entries(this.connections)) { + conn.disconnect(); + } + } + public getConnection(connection = "default"): Redis { if (!this.connections[connection]) { const currentConnection: Redis = (this.connections[connection] =