The speedtest now only executes if it is not already running

This commit is contained in:
Mathias Wagner
2022-05-08 01:36:33 +02:00
parent d430722314
commit 7874ccf419

View File

@@ -3,6 +3,8 @@ const tests = require('../controller/speedtests');
const config = require('../controller/config');
const recommendations = require("../controller/recommendations");
let isRunning = false;
function roundSpeed(bytes, elapsed) {
return Math.round((bytes * 8 / elapsed) / 10) / 100;
}
@@ -22,6 +24,7 @@ async function createRecommendations() {
}
module.exports.run = async () => {
isRunning = true;
let serverId = config.get("serverId").value;
if (serverId === "none")
serverId = undefined;
@@ -35,6 +38,8 @@ module.exports.run = async () => {
}
module.exports.create = async () => {
if (isRunning) return 500;
try {
let test = await this.run();
let ping = Math.round(test.ping.latency);
@@ -47,6 +52,7 @@ module.exports.create = async () => {
let testResult = tests.create(0, 0, 0);
console.log(`Test #${testResult} was not executed successfully. Please try reconnecting to the internet or restarting the software.`);
}
isRunning = false;
}
module.exports.removeOld = () => {