Add Cron Next Time Validation

The cron job can't be created if the year is more than 100 years in the future.
Getting the next valid time will return null if this is the case.

* add next cron validation to api
* add next cron validation to job settings page
This commit is contained in:
Alex Russell 2023-04-08 11:18:36 -06:00
commit 8b7bf65c15
No known key found for this signature in database
2 changed files with 8 additions and 4 deletions

View file

@ -1,4 +1,4 @@
using Ombi.Helpers; using Ombi.Helpers;
using Quartz; using Quartz;
namespace Ombi.Settings.Settings.Models namespace Ombi.Settings.Settings.Models
@ -104,7 +104,9 @@ namespace Ombi.Settings.Settings.Models
private static string ValidateCron(string cron) private static string ValidateCron(string cron)
{ {
if (CronExpression.IsValidExpression(cron)) CronExpression expression = new CronExpression(cron);
DateTimeOffset? nextFireUTCTime = expression.GetNextValidTimeAfter(DateTime.Now);
if (CronExpression.IsValidExpression(cron) && nextFireUTCTime != null)
{ {
return cron; return cron;
} }

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -652,7 +652,9 @@ namespace Ombi.Controllers.V1
try try
{ {
var isValid = CronExpression.IsValidExpression(expression); var isValid = CronExpression.IsValidExpression(expression);
if (!isValid) CronExpression cron = new CronExpression(expression);
DateTimeOffset? nextFireUTCTime = cron.GetNextValidTimeAfter(DateTime.Now);
if (!isValid || nextFireUTCTime == null)
{ {
return new JobSettingsViewModel return new JobSettingsViewModel
{ {