Skip to content

Commit 4836f72

Browse files
added inferDuration to calculate cron duration
1 parent 7f64bad commit 4836f72

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

server/model/maintenance.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,7 @@ class Maintenance extends BeanModel {
239239
this.beanMeta.status = "under-maintenance";
240240
clearTimeout(this.beanMeta.durationTimeout);
241241

242-
// Check if duration is still in the window. If not, use the duration from the current time to the end of the window
243-
let duration;
244-
245-
if (customDuration > 0) {
246-
duration = customDuration;
247-
} else if (this.end_date) {
248-
let d = dayjs(this.end_date).diff(dayjs(), "second");
249-
if (d < this.duration) {
250-
duration = d * 1000;
251-
}
252-
} else {
253-
duration = this.duration * 1000;
254-
}
255-
256-
if (duration === undefined && this.strategy === "recurring-interval") {
257-
duration = this.duration * 1000; // For recurring-interval, the duration needs to be defined
258-
}
242+
let duration = this.inferDuration(customDuration);
259243

260244
UptimeKumaServer.getInstance().sendMaintenanceListByUserID(this.user_id);
261245

@@ -327,6 +311,24 @@ class Maintenance extends BeanModel {
327311
}
328312
}
329313

314+
/**
315+
* Calculate the maintenance duration
316+
* @returns {number}
317+
*/
318+
319+
inferDuration(customDuration) {
320+
// Check if duration is still in the window. If not, use the duration from the current time to the end of the window
321+
if (customDuration > 0) {
322+
return customDuration;
323+
} else if (this.end_date) {
324+
let d = dayjs(this.end_date).diff(dayjs(), "second");
325+
if (d < this.duration) {
326+
return d * 1000;
327+
}
328+
}
329+
return this.duration * 1000;
330+
}
331+
330332
/**
331333
* Stop the maintenance
332334
* @returns {void}

0 commit comments

Comments
 (0)