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
26 changes: 19 additions & 7 deletions src/matches/jobs/EloCalculation.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import { Job } from "bullmq";
import { WorkerHost } from "@nestjs/bullmq";
import { Logger } from "@nestjs/common";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have our own logger handler for this. look at other loggers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched from new Logger(EloCalculation.name) to constructor-injected private readonly logger: Logger to match the project's standard pattern.

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<void> {
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;
}
}
}
4 changes: 4 additions & 0 deletions src/matches/matches.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ import { DiscordTournamentVoiceModule } from "../discord-bot/discord-tournament-
},
{
name: MatchQueues.EloCalculation,
defaultJobOptions: {
attempts: 3,
backoff: { type: "exponential", delay: 5000 },
},
},
),
BullBoardModule.forFeature(
Expand Down
Loading