Skip to content

Commit

Permalink
Fix: Schedule next beat at the start of a beat
Browse files Browse the repository at this point in the history
  • Loading branch information
chakflying committed Jul 18, 2023
1 parent 66cfbd0 commit 5b23d33
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 5b23d33

Please sign in to comment.