diff --git a/src/matches/jobs/EloCalculation.ts b/src/matches/jobs/EloCalculation.ts index ccf782c2..b76d4ef0 100644 --- a/src/matches/jobs/EloCalculation.ts +++ b/src/matches/jobs/EloCalculation.ts @@ -1,23 +1,35 @@ import { Job } from "bullmq"; import { WorkerHost } from "@nestjs/bullmq"; +import { Logger } from "@nestjs/common"; import { MatchQueues } from "../enums/MatchQueues"; import { UseQueue } from "../../utilities/QueueProcessors"; import { PostgresService } from "../../postgres/postgres.service"; @UseQueue("Matches", MatchQueues.EloCalculation) export class EloCalculation extends WorkerHost { - constructor(private readonly postgres: PostgresService) { + constructor( + private readonly logger: Logger, + private readonly postgres: PostgresService, + ) { super(); } async process(job: Job): Promise { const { matchId } = job.data; - await this.postgres.query( - ` - SELECT generate_player_elo_for_match($1) - `, - [matchId], - ); + try { + await this.postgres.query( + ` + SELECT generate_player_elo_for_match($1) + `, + [matchId], + ); + } catch (error) { + this.logger.error( + `ELO calculation failed for match ${matchId} (attempt ${job.attemptsMade + 1})`, + error, + ); + throw error; + } } } diff --git a/src/matches/matches.module.ts b/src/matches/matches.module.ts index 3a6f31fa..89c680a0 100644 --- a/src/matches/matches.module.ts +++ b/src/matches/matches.module.ts @@ -75,6 +75,10 @@ import { DiscordTournamentVoiceModule } from "../discord-bot/discord-tournament- }, { name: MatchQueues.EloCalculation, + defaultJobOptions: { + attempts: 3, + backoff: { type: "exponential", delay: 5000 }, + }, }, ), BullBoardModule.forFeature(