From d5cc35da0561de14fd9d1915583c91b5bd80b382 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 10 Oct 2024 01:15:16 +0100 Subject: [PATCH] force track players bc it never ran --- projects/backend/src/index.ts | 10 +++++----- projects/backend/src/service/player.service.ts | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/projects/backend/src/index.ts b/projects/backend/src/index.ts index 179caf4..23e6919 100644 --- a/projects/backend/src/index.ts +++ b/projects/backend/src/index.ts @@ -99,6 +99,11 @@ app.use( }) ); +/** + * Start cronjobs + */ +PlayerService.initCronjobs(); + /** * Swagger Documentation */ @@ -108,9 +113,4 @@ app.onStart(() => { console.log("Listening on port http://localhost:8080"); }); -/** - * Start cronjobs - */ -PlayerService.initCronjobs(); - app.listen(8080); diff --git a/projects/backend/src/service/player.service.ts b/projects/backend/src/service/player.service.ts index 6e3e22f..16da098 100644 --- a/projects/backend/src/service/player.service.ts +++ b/projects/backend/src/service/player.service.ts @@ -12,15 +12,26 @@ export class PlayerService { * Initialize the cron jobs */ public static initCronjobs() { + (async () => { + console.log("Tracking player statistics..."); + const players: PlayerDocument[] = await PlayerModel.find({}); + for (const player of players) { + await PlayerService.trackScoreSaberPlayer(getMidnightAlignedDate(new Date()), player); + } + console.log("Finished tracking player statistics."); + })(); + app.use( cron({ name: "player-statistics-tracker-cron", pattern: "0 1 * * *", // Every day at 00:01 (midnight) run: async () => { + console.log("Tracking player statistics..."); const players: PlayerDocument[] = await PlayerModel.find({}); for (const player of players) { await PlayerService.trackScoreSaberPlayer(getMidnightAlignedDate(new Date()), player); } + console.log("Finished tracking player statistics."); }, }) );