mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-06 13:11:13 -07:00
fix: Cron Validation (#4842)
* 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 * Add Missing Import
This commit is contained in:
parent
ca947bd302
commit
97cc42ffa8
2 changed files with 7 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
using Ombi.Helpers;
|
||||
using Quartz;
|
||||
using System;
|
||||
|
||||
namespace Ombi.Settings.Settings.Models
|
||||
{
|
||||
|
@ -104,7 +105,9 @@ namespace Ombi.Settings.Settings.Models
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -652,7 +652,9 @@ namespace Ombi.Controllers.V1
|
|||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue