Skip to content

Commit

Permalink
Validate cron before submit
Browse files Browse the repository at this point in the history
  • Loading branch information
louislam committed Apr 1, 2023
1 parent 511038b commit dbfadda
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion server/model/maintenance.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class Maintenance extends BeanModel {
if (bean.strategy === "cron") {
bean.duration = obj.durationMinutes * 60;
bean.cron = obj.cron;
this.validateCron(bean.cron);
}

if (bean.strategy.startsWith("recurring-")) {
Expand All @@ -172,11 +173,21 @@ class Maintenance extends BeanModel {
bean.weekdays = JSON.stringify(obj.weekdays);
bean.days_of_month = JSON.stringify(obj.daysOfMonth);
await bean.generateCron();
this.validateCron(bean.cron);
}

return bean;
}

/**
* Throw error if cron is invalid
* @param cron
* @returns {Promise<void>}
*/
static async validateCron(cron) {
let job = new Cron(cron, () => {});
job.stop();
}

/**
* Run the cron
*/
Expand Down

0 comments on commit dbfadda

Please sign in to comment.