Adding
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using NCrontab;
|
||||
using Serilog;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
namespace LCU.Api.Internal.DispatcherSharedLib.Utilities;
|
||||
|
||||
public static class CronHelpers
|
||||
{
|
||||
public static void SetNextScheduledRunTime(ref Job job)
|
||||
{
|
||||
var isCronSchedule = !string.IsNullOrEmpty(job.CronSchedule);
|
||||
if (isCronSchedule)
|
||||
{
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
job.NextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
|
||||
if (job.SkipHolidays)
|
||||
{
|
||||
job.NextRunTime = HolidayHelpers.HandleHolidays(job.NextRunTime);
|
||||
}
|
||||
job.JobStatus = JobStatus.ReadyToSchedule;
|
||||
}
|
||||
}
|
||||
|
||||
public static CrontabSchedule SetCronSchedule(string cron, string cronDefault)
|
||||
{
|
||||
try
|
||||
{
|
||||
return CrontabSchedule.Parse(cron);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Failure parsing cron-tab in appsettings.");
|
||||
return CrontabSchedule.Parse(cronDefault);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user