attempt to close the old socket
All checks were successful
deploy / deploy (push) Successful in 20s

This commit is contained in:
Lee 2024-01-16 15:37:58 +00:00
parent 3621941a0d
commit f621f6c5ae
2 changed files with 6 additions and 2 deletions

@ -13,6 +13,7 @@ let totalDeleted: number | undefined;
// Thee last time a map was heard // Thee last time a map was heard
let lastMap: number = Date.now(); let lastMap: number = Date.now();
let socket: WebsocketClient | undefined;
async function update() { async function update() {
if (totalCreated == undefined) { if (totalCreated == undefined) {
@ -45,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) {
@ -132,6 +133,7 @@ cron.schedule("*/1 * * * *", () => {
// 1 minute // 1 minute
if (lastMap && Date.now() - lastMap > 60_000) { if (lastMap && Date.now() - lastMap > 60_000) {
console.log("Beatsaver websocket is dead, reconnecting"); console.log("Beatsaver websocket is dead, reconnecting");
socket?.close();
connectWebsocket(); connectWebsocket();
} }
}); });

@ -12,6 +12,7 @@ let totalScores: number | undefined;
// Thee last time a score was heard // Thee last time a score was heard
let lastScore: number = Date.now(); 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
@ -50,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");
}; };
@ -160,6 +161,7 @@ cron.schedule("*/1 * * * *", () => {
// 1 minute // 1 minute
if (lastScore && Date.now() - lastScore > 60_000) { if (lastScore && Date.now() - lastScore > 60_000) {
console.log("Scoresaber websocket is dead, reconnecting"); console.log("Scoresaber websocket is dead, reconnecting");
socket?.close();
connectWebsocket(); connectWebsocket();
} }
}); });