Skip to content

Commit f183bcc

Browse files
committed
fix: add ELO calculation retry and dedicated server state recovery
1 parent c4ee3d7 commit f183bcc

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/dedicated-servers/dedicated-servers.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,17 @@ export class DedicatedServersService {
345345
await this.pingDedicatedServer(serverId);
346346
}, 10000);
347347
})
348-
.catch((error) => {
348+
.catch(async (error) => {
349349
this.logger.error(
350-
`[${serverId}] error waiting for pod to be ready`,
350+
`[${serverId}] error waiting for pod to be ready, recovering server state`,
351351
error,
352352
);
353+
await this.removeDedicatedServer(serverId).catch((removeError) => {
354+
this.logger.error(
355+
`[${serverId}] failed to clean up server after pod readiness failure`,
356+
removeError,
357+
);
358+
});
353359
});
354360

355361
return true;

src/matches/jobs/EloCalculation.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
import { Job } from "bullmq";
22
import { WorkerHost } from "@nestjs/bullmq";
3+
import { Logger } from "@nestjs/common";
34
import { MatchQueues } from "../enums/MatchQueues";
45
import { UseQueue } from "../../utilities/QueueProcessors";
56
import { PostgresService } from "../../postgres/postgres.service";
67

78
@UseQueue("Matches", MatchQueues.EloCalculation)
89
export class EloCalculation extends WorkerHost {
10+
private readonly logger = new Logger(EloCalculation.name);
11+
912
constructor(private readonly postgres: PostgresService) {
1013
super();
1114
}
1215

1316
async process(job: Job): Promise<void> {
1417
const { matchId } = job.data;
1518

16-
await this.postgres.query(
17-
`
18-
SELECT generate_player_elo_for_match($1)
19-
`,
20-
[matchId],
21-
);
19+
try {
20+
await this.postgres.query(
21+
`
22+
SELECT generate_player_elo_for_match($1)
23+
`,
24+
[matchId],
25+
);
26+
} catch (error) {
27+
this.logger.error(
28+
`ELO calculation failed for match ${matchId} (attempt ${job.attemptsMade + 1})`,
29+
error,
30+
);
31+
throw error;
32+
}
2233
}
2334
}

src/matches/matches.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ import { DiscordTournamentVoiceModule } from "../discord-bot/discord-tournament-
7575
},
7676
{
7777
name: MatchQueues.EloCalculation,
78+
defaultJobOptions: {
79+
attempts: 3,
80+
backoff: { type: "exponential", delay: 5000 },
81+
},
7882
},
7983
),
8084
BullBoardModule.forFeature(

0 commit comments

Comments
 (0)