From 4836f72cb83e239d03c7fddb7725ffd91d0b313c Mon Sep 17 00:00:00 2001 From: buzzinJohnnyBoi Date: Mon, 15 Jul 2024 16:54:56 -0400 Subject: [PATCH] added inferDuration to calculate cron duration --- server/model/maintenance.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/server/model/maintenance.js b/server/model/maintenance.js index 468cb2c4a..c1643d5a6 100644 --- a/server/model/maintenance.js +++ b/server/model/maintenance.js @@ -239,23 +239,7 @@ class Maintenance extends BeanModel { this.beanMeta.status = "under-maintenance"; clearTimeout(this.beanMeta.durationTimeout); - // Check if duration is still in the window. If not, use the duration from the current time to the end of the window - let duration; - - if (customDuration > 0) { - duration = customDuration; - } else if (this.end_date) { - let d = dayjs(this.end_date).diff(dayjs(), "second"); - if (d < this.duration) { - duration = d * 1000; - } - } else { - duration = this.duration * 1000; - } - - if (duration === undefined && this.strategy === "recurring-interval") { - duration = this.duration * 1000; // For recurring-interval, the duration needs to be defined - } + let duration = this.inferDuration(customDuration); UptimeKumaServer.getInstance().sendMaintenanceListByUserID(this.user_id); @@ -327,6 +311,24 @@ class Maintenance extends BeanModel { } } + /** + * Calculate the maintenance duration + * @returns {number} + */ + + inferDuration(customDuration) { + // Check if duration is still in the window. If not, use the duration from the current time to the end of the window + if (customDuration > 0) { + return customDuration; + } else if (this.end_date) { + let d = dayjs(this.end_date).diff(dayjs(), "second"); + if (d < this.duration) { + return d * 1000; + } + } + return this.duration * 1000; + } + /** * Stop the maintenance * @returns {void}