38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
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);
|
|
}
|
|
}
|
|
} |