mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-24 02:37:28 +01:00
Fix missing DB patch and use DATETIME as column format
This commit is contained in:
parent
30ce53f57c
commit
f390a8caf1
7
db/patch-heartbeat-add-last-notified-time.sql
Normal file
7
db/patch-heartbeat-add-last-notified-time.sql
Normal 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;
|
@ -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,
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user