Fix missing DB patch and use DATETIME as column format

This commit is contained in:
OidaTiftla 2022-01-24 21:59:25 +01:00
parent 30ce53f57c
commit f390a8caf1
3 changed files with 13 additions and 5 deletions

View file

@ -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;

View file

@ -54,6 +54,7 @@ class Database {
"patch-notification_sent_history.sql": true,
"patch-monitor-basic-auth.sql": true,
"patch-monitor-add-resend-interval.sql": true,
"patch-heartbeat-add-last-notified-time.sql": true,
}
/**

View file

@ -136,7 +136,7 @@ class Monitor extends BeanModel {
bean.monitor_id = this.id;
bean.time = R.isoDateTime(dayjs.utc());
bean.status = DOWN;
bean.lastNotifiedTime = previousBeat?.lastNotifiedTime || null; // after first update lastNotifiedTime will be undefined
bean.lastNotifiedTime = previousBeat?.lastNotifiedTime;
if (this.isUpsideDown()) {
bean.status = flipStatus(bean.status);
@ -393,7 +393,7 @@ class Monitor extends BeanModel {
await Monitor.sendNotification(isFirstBeat, this, bean);
// Set last notified time to now
bean.lastNotifiedTime = dayjs().valueOf();
bean.lastNotifiedTime = R.isoDateTime(dayjs.utc());
// Clear Status Page Cache
debug(`[${this.name}] apicache clear`);
@ -403,14 +403,14 @@ class Monitor extends BeanModel {
bean.important = false;
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) {
// 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);
// Set last notified time to now
bean.lastNotifiedTime = dayjs().valueOf();
bean.lastNotifiedTime = R.isoDateTime(dayjs.utc());
}
}
}