From 7f88aacbe735c3632a2d3664888e7a96f2c8e245 Mon Sep 17 00:00:00 2001 From: Thomas Spalinger Date: Thu, 23 Feb 2023 16:16:49 +0000 Subject: [PATCH 1/2] make monitor start() and stop() async --- server/model/monitor.js | 4 ++-- server/server.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 4bb859e9a..c7388607d 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -199,7 +199,7 @@ class Monitor extends BeanModel { * Start monitor * @param {Server} io Socket server instance */ - start(io) { + async start(io) { let previousBeat = null; let retries = 0; @@ -836,7 +836,7 @@ class Monitor extends BeanModel { } /** Stop monitor */ - stop() { + async stop() { clearTimeout(this.heartbeatInterval); this.isStop = true; diff --git a/server/server.js b/server/server.js index 18598171e..1dd012afa 100644 --- a/server/server.js +++ b/server/server.js @@ -872,7 +872,7 @@ let needSetup = false; log.info("manage", `Delete Monitor: ${monitorID} User ID: ${socket.userID}`); if (monitorID in server.monitorList) { - server.monitorList[monitorID].stop(); + await server.monitorList[monitorID].stop(); delete server.monitorList[monitorID]; } @@ -1694,11 +1694,11 @@ async function startMonitor(userID, monitorID) { ]); if (monitor.id in server.monitorList) { - server.monitorList[monitor.id].stop(); + await server.monitorList[monitor.id].stop(); } server.monitorList[monitor.id] = monitor; - monitor.start(io); + await monitor.start(io); } /** @@ -1728,7 +1728,7 @@ async function pauseMonitor(userID, monitorID) { ]); if (monitorID in server.monitorList) { - server.monitorList[monitorID].stop(); + await server.monitorList[monitorID].stop(); } } @@ -1741,7 +1741,7 @@ async function startMonitors() { } for (let monitor of list) { - monitor.start(io); + await monitor.start(io); // Give some delays, so all monitors won't make request at the same moment when just start the server. await sleep(getRandomInt(300, 1000)); } @@ -1762,7 +1762,7 @@ async function shutdownFunction(signal) { log.info("server", "Stopping all monitors"); for (let id in server.monitorList) { let monitor = server.monitorList[id]; - monitor.stop(); + await monitor.stop(); } await sleep(2000); await Database.close(); From dc3abc68f0c90681727c7ea574a35f8588174108 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 30 Jan 2024 17:54:04 +0100 Subject: [PATCH 2/2] Fixed type anotation --- server/model/monitor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 30c631a75..0c322b92c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -324,7 +324,7 @@ class Monitor extends BeanModel { /** * Start monitor * @param {Server} io Socket server instance - * @returns {void} + * @returns {Promise} */ async start(io) { let previousBeat = null;