Fix missing DB patch and use DATETIME as column format
This commit is contained in:
parent
30ce53f57c
commit
f390a8caf1
|
@ -0,0 +1,7 @@
|
||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE heartbeat
|
||||||
|
ADD last_notified_time DATETIME default null;
|
||||||
|
|
||||||
|
COMMIT;
|
|
@ -54,6 +54,7 @@ class Database {
|
||||||
"patch-notification_sent_history.sql": true,
|
"patch-notification_sent_history.sql": true,
|
||||||
"patch-monitor-basic-auth.sql": true,
|
"patch-monitor-basic-auth.sql": true,
|
||||||
"patch-monitor-add-resend-interval.sql": true,
|
"patch-monitor-add-resend-interval.sql": true,
|
||||||
|
"patch-heartbeat-add-last-notified-time.sql": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -136,7 +136,7 @@ class Monitor extends BeanModel {
|
||||||
bean.monitor_id = this.id;
|
bean.monitor_id = this.id;
|
||||||
bean.time = R.isoDateTime(dayjs.utc());
|
bean.time = R.isoDateTime(dayjs.utc());
|
||||||
bean.status = DOWN;
|
bean.status = DOWN;
|
||||||
bean.lastNotifiedTime = previousBeat?.lastNotifiedTime || null; // after first update lastNotifiedTime will be undefined
|
bean.lastNotifiedTime = previousBeat?.lastNotifiedTime;
|
||||||
|
|
||||||
if (this.isUpsideDown()) {
|
if (this.isUpsideDown()) {
|
||||||
bean.status = flipStatus(bean.status);
|
bean.status = flipStatus(bean.status);
|
||||||
|
@ -393,7 +393,7 @@ class Monitor extends BeanModel {
|
||||||
await Monitor.sendNotification(isFirstBeat, this, bean);
|
await Monitor.sendNotification(isFirstBeat, this, bean);
|
||||||
|
|
||||||
// Set last notified time to now
|
// Set last notified time to now
|
||||||
bean.lastNotifiedTime = dayjs().valueOf();
|
bean.lastNotifiedTime = R.isoDateTime(dayjs.utc());
|
||||||
|
|
||||||
// Clear Status Page Cache
|
// Clear Status Page Cache
|
||||||
debug(`[${this.name}] apicache clear`);
|
debug(`[${this.name}] apicache clear`);
|
||||||
|
@ -403,14 +403,14 @@ class Monitor extends BeanModel {
|
||||||
bean.important = false;
|
bean.important = false;
|
||||||
|
|
||||||
if (bean.status === DOWN && this.resendInterval > 0) {
|
if (bean.status === DOWN && this.resendInterval > 0) {
|
||||||
timeSinceLastNotified = (dayjs().valueOf() - (bean.lastNotifiedTime || 0)) / 60; // divide by 60 to convert from seconds to minutes
|
let timeSinceLastNotified = (dayjs.utc().valueOf() - (bean.lastNotifiedTime == null ? 0 : dayjs.utc(bean.lastNotifiedTime).valueOf())) / 1000 / 60; // divide by 1000 to convert from milliseconds to seconds and divide by 60 to convert from seconds to minutes
|
||||||
if (timeSinceLastNotified >= this.resendInterval) {
|
if (timeSinceLastNotified >= this.resendInterval) {
|
||||||
// Send notification again, because we are still DOWN
|
// Send notification again, because we are still DOWN
|
||||||
debug(`[${this.name}] sendNotification`);
|
debug(`[${this.name}] sendNotification again: lastNotifiedTime: ${bean.lastNotifiedTime} | current time: ${R.isoDateTime(dayjs.utc())}`);
|
||||||
await Monitor.sendNotification(isFirstBeat, this, bean);
|
await Monitor.sendNotification(isFirstBeat, this, bean);
|
||||||
|
|
||||||
// Set last notified time to now
|
// Set last notified time to now
|
||||||
bean.lastNotifiedTime = dayjs().valueOf();
|
bean.lastNotifiedTime = R.isoDateTime(dayjs.utc());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue