From 33cc96f918bca0f49a611cf0cfb7edd5fa4597b0 Mon Sep 17 00:00:00 2001 From: Nelson Chan <3271800+chakflying@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:11:04 +0800 Subject: [PATCH] Fix: subtract time taken to run heartbeat (#3072) --- server/model/monitor.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index adeeab83..284a5ccc 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -948,7 +948,15 @@ class Monitor extends BeanModel { if (! this.isStop) { log.debug("monitor", `[${this.name}] SetTimeout for next check.`); - this.heartbeatInterval = setTimeout(safeBeat, beatInterval * 1000); + + let intervalRemainingMs = Math.max( + 1, + beatInterval * 1000 - dayjs().diff(dayjs.utc(bean.time)) + ); + + log.debug("monitor", `[${this.name}] Next heartbeat in: ${intervalRemainingMs}ms`); + + this.heartbeatInterval = setTimeout(safeBeat, intervalRemainingMs); } else { log.info("monitor", `[${this.name}] isStop = true, no next check.`); }