Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/matches/match-assistant/match-assistant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/redis/redis-manager/redis-manager.service.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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] =
Expand Down
Loading