Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ export class AppModule implements OnApplicationBootstrap {

public async onApplicationBootstrap() {
try {
void this.discordBot.setup();
this.discordBot.setup().catch((error) => {
this.logger.error("Discord bot setup failed", error);
});
await this.typesense.setup();
await this.system.detectFeatures();
} catch (error) {
Expand Down
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
124 changes: 75 additions & 49 deletions src/matches/matches.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,67 +125,93 @@ export class MatchesModule implements NestModule {
return;
}

void scheduleMatchQueue.add(
CheckForScheduledMatches.name,
{},
{
repeat: {
pattern: "* * * * *",
scheduleMatchQueue
.add(
CheckForScheduledMatches.name,
{},
{
repeat: {
pattern: "* * * * *",
},
},
},
);
)
.catch((err) => {
Comment thread
lukepolo marked this conversation as resolved.
Outdated
this.logger.error("Failed to add CheckForScheduledMatches job", err);
});

void scheduleMatchQueue.add(
CancelExpiredMatches.name,
{},
{
repeat: {
pattern: "* * * * *",
scheduleMatchQueue
.add(
CancelExpiredMatches.name,
{},
{
repeat: {
pattern: "* * * * *",
},
},
},
);
)
.catch((err) => {
this.logger.error("Failed to add CancelExpiredMatches job", err);
});

void scheduleMatchQueue.add(
RemoveCancelledMatches.name,
{},
{
repeat: {
pattern: "* * * * *",
scheduleMatchQueue
.add(
RemoveCancelledMatches.name,
{},
{
repeat: {
pattern: "* * * * *",
},
},
},
);
)
.catch((err) => {
this.logger.error("Failed to add RemoveCancelledMatches job", err);
});

void matchServersQueue.add(
CheckForTournamentStart.name,
{},
{
repeat: {
pattern: "* * * * *",
matchServersQueue
.add(
CheckForTournamentStart.name,
{},
{
repeat: {
pattern: "* * * * *",
},
},
},
);
)
.catch((err) => {
this.logger.error("Failed to add CheckForTournamentStart job", err);
});

void matchServersQueue.add(
CleanAbandonedMatches.name,
{},
{
repeat: {
pattern: "0 0 * * *",
matchServersQueue
.add(
CleanAbandonedMatches.name,
{},
{
repeat: {
pattern: "0 0 * * *",
},
},
},
);
)
.catch((err) => {
this.logger.error("Failed to add CleanAbandonedMatches job", err);
});

void matchServersQueue.add(
CancelInvalidTournaments.name,
{},
{
repeat: {
pattern: "* * * * *",
matchServersQueue
.add(
CancelInvalidTournaments.name,
{},
{
repeat: {
pattern: "* * * * *",
},
},
},
);
)
.catch((err) => {
this.logger.error("Failed to add CancelInvalidTournaments job", err);
});

void this.generatePlayerRatings();
this.generatePlayerRatings().catch((err) => {
this.logger.error("Failed to generate player ratings", err);
});
}

/**
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
16 changes: 12 additions & 4 deletions src/sockets/sockets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ export class SocketsService {

const sub = this.redisManager.getConnection("sub");

void sub.subscribe("broadcast-message");
void sub.subscribe("send-message-to-steam-id");
sub.subscribe("broadcast-message").catch((err) => {
this.logger.error("Failed to subscribe to broadcast-message", err);
});
sub.subscribe("send-message-to-steam-id").catch((err) => {
this.logger.error("Failed to subscribe to send-message-to-steam-id", err);
});
sub.on("message", (channel, message) => {
const { steamId, event, data } = JSON.parse(message) as {
steamId: string;
Expand All @@ -44,10 +48,14 @@ export class SocketsService {

switch (channel) {
case "broadcast-message":
void this.broadcastMessage(event, data);
this.broadcastMessage(event, data).catch((err) => {
this.logger.error("broadcast-message error", err);
});
break;
case "send-message-to-steam-id":
void this.sendMessageToSteamId(steamId, event, data);
this.sendMessageToSteamId(steamId, event, data).catch((err) => {
this.logger.error("send-message-to-steam-id error", err);
});
break;
}
});
Expand Down
Loading