add tracking cooldown
Some checks failed
Deploy Backend / deploy (push) Has been cancelled
Deploy Website / deploy (push) Successful in 3m18s

This commit is contained in:
Lee 2024-10-11 18:47:33 +01:00
parent 29f9b305e7
commit d16cf9e4af
2 changed files with 13 additions and 0 deletions

@ -17,6 +17,7 @@ import { PlayerService } from "./service/player.service";
import { cron } from "@elysiajs/cron";
import { PlayerDocument, PlayerModel } from "./model/player";
import { scoresaberService } from "@ssr/common/service/impl/scoresaber";
import { delay } from "@ssr/common/utils/utils";
// Load .env file
dotenv.config({
@ -36,6 +37,8 @@ app.use(
timezone: "Europe/London",
run: async () => {
const pages = 10;
const cooldown = 60_000 / 200; // 200 requests per minute
let toTrack: PlayerDocument[] = await PlayerModel.find({});
const toRemoveIds: string[] = [];
@ -63,6 +66,7 @@ app.use(
console.log(`Tracking ${toTrack.length} player statistics...`);
for (const player of toTrack) {
await PlayerService.trackScoreSaberPlayer(player);
await delay(cooldown);
}
console.log("Finished tracking player statistics.");
},

@ -4,3 +4,12 @@
export function isProduction() {
return process.env.NODE_ENV === "production";
}
/**
* Delays a promise
*
* @param ms the number of milliseconds to delay
*/
export function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}