always ensure the frontpage of players is being tracked
All checks were successful
Deploy Backend / deploy (push) Successful in 3m19s

This commit is contained in:
Lee 2024-10-11 03:47:54 +01:00
parent 0e4feb4181
commit b059ee3537
3 changed files with 16 additions and 3 deletions

@ -7,4 +7,4 @@ export class NotFoundError extends Error {
) { ) {
super(message); super(message);
} }
} }

@ -7,4 +7,4 @@ export class RateLimitError extends Error {
) { ) {
super(message); super(message);
} }
} }

@ -16,7 +16,7 @@ import PlayerController from "./controller/player.controller";
import { PlayerService } from "./service/player.service"; import { PlayerService } from "./service/player.service";
import { cron } from "@elysiajs/cron"; import { cron } from "@elysiajs/cron";
import { PlayerDocument, PlayerModel } from "./model/player"; import { PlayerDocument, PlayerModel } from "./model/player";
import { getMidnightAlignedDate } from "@ssr/common/utils/time-utils"; import { scoresaberService } from "@ssr/common/service/impl/scoresaber";
// Load .env file // Load .env file
dotenv.config({ dotenv.config({
@ -35,6 +35,19 @@ app.use(
pattern: "1 0 * * *", // Every day at 00:01 (London time) pattern: "1 0 * * *", // Every day at 00:01 (London time)
timezone: "Europe/London", timezone: "Europe/London",
run: async () => { run: async () => {
console.log("Fetching first page of players from ScoreSaber...");
const page = await scoresaberService.lookupPlayers(1);
if (page === undefined) {
console.log("Failed to fetch players from ScoreSaber");
return;
}
for (const player of page.players) {
await PlayerService.getPlayer(player.id, true);
}
console.log("All players on the front page are now being tracked :)");
// ---
console.log("Tracking player statistics..."); console.log("Tracking player statistics...");
const players: PlayerDocument[] = await PlayerModel.find({}); const players: PlayerDocument[] = await PlayerModel.find({});
for (const player of players) { for (const player of players) {