A flag added to check if a haertbeat is ongoing (#154)

This commit is contained in:
Udith Indrakantha
2022-07-07 12:16:25 +05:30
committed by GitHub
parent 964cd6a206
commit d21cf1fdd3

View File

@@ -73,6 +73,7 @@ class MessageBoard {
await this.hostClient.updateRegInfo(this.activeInstanceCount, this.cfg.version);
this.db.close();
let ongoingHeartbeat = false;
// Check for instance expiry.
this.xrplApi.on(evernode.XrplApiEvents.LEDGER, async (e) => {
this.lastValidatedLedgerIndex = e.ledger_index;
@@ -80,9 +81,10 @@ class MessageBoard {
const currentMoment = await this.hostClient.getMoment(e.ledger_index);
// Sending heartbeat every CONF_HOST_HEARTBEAT_FREQ moments.
if (this.lastHeartbeatMoment === 0 || (currentMoment % this.hostClient.config.hostHeartbeatFreq === 0 && currentMoment !== this.lastHeartbeatMoment)) {
console.log(`Reporting heartbeat at Moment ${this.lastHeartbeatMoment}...`)
if ( ! ongoingHeartbeat &&
(this.lastHeartbeatMoment === 0 || (currentMoment % this.hostClient.config.hostHeartbeatFreq === 0 && currentMoment !== this.lastHeartbeatMoment))) {
ongoingHeartbeat = true;
console.log(`Reporting heartbeat at Moment ${this.lastHeartbeatMoment}...`);
try {
await this.hostClient.heartbeat();
@@ -94,6 +96,9 @@ class MessageBoard {
else
console.log("Heartbeat tx error", err);
}
finally {
ongoingHeartbeat = false;
}
}
// Filter out instances which needed to be expired and destroy them.