add tracking cooldown
This commit is contained in:
parent
29f9b305e7
commit
d16cf9e4af
@ -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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user