mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-01-06 21:19:39 -06:00
The speedtest now only executes if it is not already running
This commit is contained in:
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user