Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Added leaderboard to import completed events
Browse files Browse the repository at this point in the history
Fixes #299
  • Loading branch information
ThomasK33 committed Feb 1, 2021
1 parent 1b976f1 commit d4dfe97
Show file tree
Hide file tree
Showing 9 changed files with 9,025 additions and 1,352 deletions.
522 changes: 339 additions & 183 deletions services/historization/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion services/historization/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "historization",
"version": "1.7.2",
"version": "1.7.3",
"description": "A historization service responsible for persisting info",
"author": {
"name": "Thomas Kosiewski"
Expand Down
29 changes: 22 additions & 7 deletions services/historization/src/services/leaderboardPersistor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,35 @@ export class LeaderboardPersistor {
async storeLeaderboard(event: ImportCompletedEvent) {
// Fetch corresponding leaderboard from redis
const leaderboardType = event.leaderboardType;
const rawLeaderboard = await this.redis.getAsync(
`ul:leaderboard:${leaderboardType}`,
);

if (!rawLeaderboard) {
this.logger.error("No leaderboard found in redis", {
const leaderboard: ULLeaderboard | undefined =
event.args?.leaderboard ||
(await (async () => {
const rawLeaderboard = await this.redis.getAsync(
`ul:leaderboard:${leaderboardType}`,
);

if (!rawLeaderboard) {
this.logger.error("No leaderboard found in redis", {
leaderboardType,
event,
});
return;
}

const leaderboard: ULLeaderboard = JSON.parse(rawLeaderboard);

return leaderboard;
})());

if (!leaderboard) {
this.logger.error("Leaderboard is not set", {
leaderboardType,
event,
});
return;
}

const leaderboard: ULLeaderboard = JSON.parse(rawLeaderboard);

// Fetch current users from postgres
const userRepo = await this.postgres.getUserRepo();
const steamids = (
Expand Down
Loading

0 comments on commit d4dfe97

Please sign in to comment.