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