Short-circuit heartbeat when alive
This commit is contained in:
parent
504d89638b
commit
f2f1fee6f1
@ -21,26 +21,28 @@ export class Heart {
|
|||||||
* activity. Failures are logged as warnings.
|
* activity. Failures are logged as warnings.
|
||||||
*/
|
*/
|
||||||
public beat(): void {
|
public beat(): void {
|
||||||
if (!this.alive()) {
|
if (this.alive()) {
|
||||||
logger.trace("heartbeat")
|
return
|
||||||
fs.writeFile(this.heartbeatPath, "").catch((error) => {
|
|
||||||
logger.warn(error.message)
|
|
||||||
})
|
|
||||||
this.lastHeartbeat = Date.now()
|
|
||||||
if (typeof this.heartbeatTimer !== "undefined") {
|
|
||||||
clearTimeout(this.heartbeatTimer)
|
|
||||||
}
|
|
||||||
this.heartbeatTimer = setTimeout(() => {
|
|
||||||
this.isActive()
|
|
||||||
.then((active) => {
|
|
||||||
if (active) {
|
|
||||||
this.beat()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
logger.warn(error.message)
|
|
||||||
})
|
|
||||||
}, this.heartbeatInterval)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.trace("heartbeat")
|
||||||
|
fs.writeFile(this.heartbeatPath, "").catch((error) => {
|
||||||
|
logger.warn(error.message)
|
||||||
|
})
|
||||||
|
this.lastHeartbeat = Date.now()
|
||||||
|
if (typeof this.heartbeatTimer !== "undefined") {
|
||||||
|
clearTimeout(this.heartbeatTimer)
|
||||||
|
}
|
||||||
|
this.heartbeatTimer = setTimeout(() => {
|
||||||
|
this.isActive()
|
||||||
|
.then((active) => {
|
||||||
|
if (active) {
|
||||||
|
this.beat()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
logger.warn(error.message)
|
||||||
|
})
|
||||||
|
}, this.heartbeatInterval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user