This commit is contained in:
@ -1,33 +1,11 @@
|
||||
import { PlayerDocument, PlayerModel } from "../model/player";
|
||||
import { NotFoundError } from "../error/not-found-error";
|
||||
import { cron } from "@elysiajs/cron";
|
||||
import { app } from "../index";
|
||||
import { getDaysAgoDate, getMidnightAlignedDate } from "@ssr/common/utils/time-utils";
|
||||
import { scoresaberService } from "@ssr/common/service/impl/scoresaber";
|
||||
import ScoreSaberPlayerToken from "@ssr/common/types/token/scoresaber/score-saber-player-token";
|
||||
import { InternalServerError } from "../error/internal-server-error";
|
||||
|
||||
export class PlayerService {
|
||||
/**
|
||||
* Initialize the cron jobs
|
||||
*/
|
||||
public static initCronjobs() {
|
||||
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.");
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player from the database.
|
||||
*
|
||||
|
Reference in New Issue
Block a user