8 Commits

Author SHA1 Message Date
564cfd11cc fix(deps): update dependency axios to v1.6.8 2024-04-17 15:01:04 +00:00
f621f6c5ae attempt to close the old socket
All checks were successful
deploy / deploy (push) Successful in 20s
2024-01-16 15:37:58 +00:00
3621941a0d e
All checks were successful
deploy / deploy (push) Successful in 22s
2024-01-16 15:36:30 +00:00
fe15f660e6 e
All checks were successful
deploy / deploy (push) Successful in 36s
2024-01-16 15:33:50 +00:00
5c2416e7ee e
Some checks failed
deploy / deploy (push) Has been cancelled
2024-01-16 15:33:11 +00:00
46efd6b6dc Merge branch 'master' of https://git.fascinated.cc/Fascinated/beatsaber-metrics-tracker
Some checks failed
deploy / deploy (push) Failing after 23s
2024-01-16 15:31:32 +00:00
7749a570d6 impl a simple dead socket handler 2024-01-16 15:29:59 +00:00
b9dedbc603 switch to pnpm 2023-11-08 06:45:46 +00:00
8 changed files with 1488 additions and 99 deletions

4
.gitignore vendored
View File

@ -144,3 +144,7 @@ dist
# Built Visual Studio Code Extensions # Built Visual Studio Code Extensions
*.vsix *.vsix
# lock files
package-lock.json
yarn.lock

View File

@ -1,9 +1,10 @@
FROM node:alpine FROM fascinated/docker-images:node-pnpm-latest
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY package*.json ./ COPY package.json pnpm-lock.yaml ./
RUN npm install RUN pnpm install
COPY . . COPY . .
RUN npx tsc -b RUN pnpm run build
ENV PORT=80 ENV PORT=80
EXPOSE 80 EXPOSE 80
CMD [ "npm", "start" ] CMD [ "pnpm", "start" ]

14
package-lock.json generated
View File

@ -296,11 +296,11 @@
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
}, },
"node_modules/axios": { "node_modules/axios": {
"version": "1.6.2", "version": "1.6.8",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
"integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
"dependencies": { "dependencies": {
"follow-redirects": "^1.15.0", "follow-redirects": "^1.15.6",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"proxy-from-env": "^1.1.0" "proxy-from-env": "^1.1.0"
} }
@ -723,9 +723,9 @@
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
}, },
"node_modules/follow-redirects": { "node_modules/follow-redirects": {
"version": "1.15.3", "version": "1.15.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"funding": [ "funding": [
{ {
"type": "individual", "type": "individual",

View File

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"start": "node dist/index.js", "start": "node dist/index.js",
"tsc": "tsc -w", "tsc": "tsc -w",
"build": "tsc",
"dev": "nodemon dist/index.js" "dev": "nodemon dist/index.js"
}, },
"author": "", "author": "",

1358
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,10 @@ let totalUpdated: number | undefined;
let totalCreated: number | undefined; let totalCreated: number | undefined;
let totalDeleted: number | undefined; let totalDeleted: number | undefined;
// Thee last time a map was heard
let lastMap: number = Date.now();
let socket: WebsocketClient | undefined;
async function update() { async function update() {
if (totalCreated == undefined) { if (totalCreated == undefined) {
throw new Error("Total created is undefined"); throw new Error("Total created is undefined");
@ -42,7 +46,7 @@ async function update() {
} }
async function connectWebsocket() { async function connectWebsocket() {
const socket = new WebsocketClient(WEBSOCKET_URL); socket = new WebsocketClient(WEBSOCKET_URL);
await connectMongo(); await connectMongo();
let beatSaver = await BeatSaverSchema.findOne({ _id: "beatsaver" }); let beatSaver = await BeatSaverSchema.findOne({ _id: "beatsaver" });
if (!beatSaver) { if (!beatSaver) {
@ -125,3 +129,11 @@ async function connectWebsocket() {
connectWebsocket(); connectWebsocket();
cron.schedule("*/5 * * * *", update); cron.schedule("*/5 * * * *", update);
cron.schedule("*/1 * * * *", () => {
// 1 minute
if (lastMap && Date.now() - lastMap > 60_000) {
console.log("Beatsaver websocket is dead, reconnecting");
socket?.close();
connectWebsocket();
}
});

View File

@ -10,6 +10,10 @@ import { normalizedRegionName } from "../utils/regionUtils";
let totalScores: number | undefined; let totalScores: number | undefined;
// Thee last time a score was heard
let lastScore: number = Date.now();
let socket: WebsocketClient | undefined;
/** /**
* Updates the player count and adds data to influx * Updates the player count and adds data to influx
*/ */
@ -47,7 +51,7 @@ async function connectWebsocket() {
// set total scores to the current total plays in the database // set total scores to the current total plays in the database
totalScores = leaderboard?.totalPlays || 0; totalScores = leaderboard?.totalPlays || 0;
const socket = new WebsocketClient("wss://scoresaber.com/ws"); socket = new WebsocketClient("wss://scoresaber.com/ws");
socket.onopen = () => { socket.onopen = () => {
console.log("Connected to scoresaber websocket"); console.log("Connected to scoresaber websocket");
}; };
@ -62,6 +66,7 @@ async function connectWebsocket() {
}; };
socket.onmessage = async (message) => { socket.onmessage = async (message) => {
lastScore = Date.now();
const data = message.data; const data = message.data;
let json; let json;
try { try {
@ -152,3 +157,11 @@ async function connectWebsocket() {
update(); update();
connectWebsocket(); connectWebsocket();
cron.schedule("*/1 * * * *", update); cron.schedule("*/1 * * * *", update);
cron.schedule("*/1 * * * *", () => {
// 1 minute
if (lastScore && Date.now() - lastScore > 60_000) {
console.log("Scoresaber websocket is dead, reconnecting");
socket?.close();
connectWebsocket();
}
});