mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 22:03:15 -07:00
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:
parent
c262b7c22b
commit
8b7bf65c15
2 changed files with 8 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
using Ombi.Helpers;
|
||||
using Ombi.Helpers;
|
||||
using Quartz;
|
||||
|
||||
namespace Ombi.Settings.Settings.Models
|
||||
|
@ -104,7 +104,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;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
@ -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