From 5b23d332abca48af37b11985f5bf48d9d684bec1 Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Sat, 15 Apr 2023 03:05:29 +0800 Subject: [PATCH] Fix: Schedule next beat at the start of a beat --- server/model/monitor.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 06f6a7d5ea..fe34145ca1 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -266,6 +266,14 @@ class Monitor extends BeanModel { } } + // Schedule next beat + if (! this.isStop) { + log.debug("monitor", `[${this.name}] SetTimeout for next check.`); + this.heartbeatInterval = setTimeout(safeBeat, beatInterval * 1000); + } else { + log.info("monitor", `[${this.name}] isStop = true, no next check.`); + } + // Expose here for prometheus update // undefined if not https let tlsInfo = undefined; @@ -571,6 +579,7 @@ class Monitor extends BeanModel { // No need to insert successful heartbeat for push type, so end here retries = 0; log.debug("monitor", `[${this.name}] timeout = ${timeout}`); + clearTimeout(this.heartbeatInterval); this.heartbeatInterval = setTimeout(safeBeat, timeout); return; } @@ -910,14 +919,6 @@ class Monitor extends BeanModel { this.prometheus?.update(bean, tlsInfo); previousBeat = bean; - - if (! this.isStop) { - log.debug("monitor", `[${this.name}] SetTimeout for next check.`); - this.heartbeatInterval = setTimeout(safeBeat, beatInterval * 1000); - } else { - log.info("monitor", `[${this.name}] isStop = true, no next check.`); - } - }; /** Get a heartbeat and handle errors */