mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-09 03:28:45 +08:00
Feat: Retries persistence (#3814)
* Feat: Retries persistence * Fix: Set duration for first beat of push monitor * Feat: Update UptimeCalculator in push route * Fix: Handle resend in push route * Chore: Remove debug log
This commit is contained in:
@@ -29,13 +29,14 @@ class Heartbeat extends BeanModel {
|
||||
*/
|
||||
toJSON() {
|
||||
return {
|
||||
monitorID: this.monitor_id,
|
||||
status: this.status,
|
||||
time: this.time,
|
||||
msg: this.msg,
|
||||
ping: this.ping,
|
||||
important: this.important,
|
||||
duration: this.duration,
|
||||
monitorID: this._monitorId,
|
||||
status: this._status,
|
||||
time: this._time,
|
||||
msg: this._msg,
|
||||
ping: this._ping,
|
||||
important: this._important,
|
||||
duration: this._duration,
|
||||
retries: this._retries,
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -361,6 +361,9 @@ class Monitor extends BeanModel {
|
||||
previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [
|
||||
this.id,
|
||||
]);
|
||||
if (previousBeat) {
|
||||
retries = previousBeat.retries;
|
||||
}
|
||||
}
|
||||
|
||||
const isFirstBeat = !previousBeat;
|
||||
@@ -632,6 +635,7 @@ class Monitor extends BeanModel {
|
||||
// If the previous beat was down or pending we use the regular
|
||||
// beatInterval/retryInterval in the setTimeout further below
|
||||
if (previousBeat.status !== (this.isUpsideDown() ? DOWN : UP) || msSinceLastBeat > beatInterval * 1000 + bufferTime) {
|
||||
bean.duration = Math.round(msSinceLastBeat / 1000);
|
||||
throw new Error("No heartbeat in the time window");
|
||||
} else {
|
||||
let timeout = beatInterval * 1000 - msSinceLastBeat;
|
||||
@@ -647,6 +651,7 @@ class Monitor extends BeanModel {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
bean.duration = beatInterval;
|
||||
throw new Error("No heartbeat in the time window");
|
||||
}
|
||||
|
||||
@@ -915,9 +920,14 @@ class Monitor extends BeanModel {
|
||||
} else if ((this.maxretries > 0) && (retries < this.maxretries)) {
|
||||
retries++;
|
||||
bean.status = PENDING;
|
||||
} else {
|
||||
// Continue counting retries during DOWN
|
||||
retries++;
|
||||
}
|
||||
}
|
||||
|
||||
bean.retries = retries;
|
||||
|
||||
log.debug("monitor", `[${this.name}] Check isImportant`);
|
||||
let isImportant = Monitor.isImportantBeat(isFirstBeat, previousBeat?.status, bean.status);
|
||||
|
||||
@@ -1437,10 +1447,7 @@ class Monitor extends BeanModel {
|
||||
* @returns {Promise<LooseObject<any>>} Previous heartbeat
|
||||
*/
|
||||
static async getPreviousHeartbeat(monitorID) {
|
||||
return await R.getRow(`
|
||||
SELECT ping, status, time FROM heartbeat
|
||||
WHERE id = (select MAX(id) from heartbeat where monitor_id = ?)
|
||||
`, [
|
||||
return await R.findOne("heartbeat", " id = (select MAX(id) from heartbeat where monitor_id = ?)", [
|
||||
monitorID
|
||||
]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user