diff --git a/package-lock.json b/package-lock.json index 918c3dd04..4af4f60df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "command-exists": "~1.2.9", "compare-versions": "~3.6.0", "compression": "~1.7.4", - "croner": "~6.0.5", + "croner": "^8.1.0", "dayjs": "~1.11.5", "dev-null": "^0.1.1", "dotenv": "~16.0.3", @@ -6738,12 +6738,11 @@ } }, "node_modules/croner": { - "version": "6.0.7", - "resolved": "https://registry.npmjs.org/croner/-/croner-6.0.7.tgz", - "integrity": "sha512-k3Xx3Rcclfr60Yx4TmvsF3Yscuiql8LSvYLaphTsaq5Hk8La4Z/udmUANMOTKpgGGroI2F6/XOr9cU9OFkYluQ==", - "license": "MIT", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/croner/-/croner-8.1.0.tgz", + "integrity": "sha512-sz990XOUPR8dG/r5BRKMBd15MYDDUu8oeSaxFD5DqvNgHSZw8Psd1s689/IGET7ezxRMiNlCIyGeY1Gvxp/MLg==", "engines": { - "node": ">=6.0" + "node": ">=18.0" } }, "node_modules/cronstrue": { diff --git a/package.json b/package.json index 31a89a7c7..215362832 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "command-exists": "~1.2.9", "compare-versions": "~3.6.0", "compression": "~1.7.4", - "croner": "~6.0.5", + "croner": "^8.1.0", "dayjs": "~1.11.5", "dev-null": "^0.1.1", "dotenv": "~16.0.3", diff --git a/server/model/maintenance.js b/server/model/maintenance.js index 516c03777..7aa824ffe 100644 --- a/server/model/maintenance.js +++ b/server/model/maintenance.js @@ -253,6 +253,10 @@ class Maintenance extends BeanModel { duration = this.duration * 1000; } + if (duration === undefined && this.strategy === "recurring-interval") { + duration = this.duration * 1000; + } + UptimeKumaServer.getInstance().sendMaintenanceListByUserID(this.user_id); this.beanMeta.durationTimeout = setTimeout(() => { @@ -263,9 +267,20 @@ class Maintenance extends BeanModel { }; // Create Cron - this.beanMeta.job = new Cron(this.cron, { - timezone: await this.getTimezone(), - }, startEvent); + if (this.strategy === "recurring-interval") { + const startDate = dayjs(this.startDate); + const [ hour, minute ] = this.startTime.split(":"); + const startDateTime = startDate.hour(hour).minute(minute); + this.beanMeta.job = new Cron(this.cron, { + timezone: await this.getTimezone(), + interval: this.interval_day * 24 * 60 * 60, + startAt: startDateTime.toISOString(), + }, startEvent); + } else { + this.beanMeta.job = new Cron(this.cron, { + timezone: await this.getTimezone(), + }, startEvent); + } // Continue if the maintenance is still in the window let runningTimeslot = this.getRunningTimeslot(); @@ -395,10 +410,7 @@ class Maintenance extends BeanModel { } else if (!this.strategy.startsWith("recurring-")) { this.cron = ""; } else if (this.strategy === "recurring-interval") { - let array = this.start_time.split(":"); - let hour = parseInt(array[0]); - let minute = parseInt(array[1]); - this.cron = minute + " " + hour + " */" + this.interval_day + " * *"; + this.cron = "* * * * *"; this.duration = this.calcDuration(); log.debug("maintenance", "Cron: " + this.cron); log.debug("maintenance", "Duration: " + this.duration);