This commit is contained in:
LouisLam
2021-06-25 21:55:49 +08:00
parent c22e3050fb
commit 0a4fb45a8c
17 changed files with 1533 additions and 0 deletions

33
server/model/monitor.js Normal file
View File

@@ -0,0 +1,33 @@
const dayjs = require("dayjs");
const {BeanModel} = require("redbean-node/dist/bean-model");
class Monitor extends BeanModel {
toJSON() {
return {
id: this.id,
name: this.name,
url: this.url,
upRate: this.upRate,
active: this.active,
type: this.type,
interval: this.interval,
};
}
start(io) {
const beat = () => {
console.log(`Monitor ${this.id}: Heartbeat`)
io.to(this.user_id).emit("heartbeat", dayjs().unix());
}
beat();
this.heartbeatInterval = setInterval(beat, this.interval * 1000);
}
stop() {
clearInterval(this.heartbeatInterval)
}
}
module.exports = Monitor;