using Azaion.Repository.Jobs; using Quartz; namespace Azaion.Repository.Extensions { public static class QuartzJobConfigHelper { public static IServiceCollectionQuartzConfigurator RegisterJob(this IServiceCollectionQuartzConfigurator q, string cron, TimeSpan? startForDebug = null) where T: BaseJob { var jobName = typeof(T).Name; var jobKey = new JobKey(jobName); q.AddJob(jobKey); q.AddTrigger(t => t.WithIdentity($"{jobName}_TRIGGER") .ForJob(jobKey) #if DEBUG .StartAt(DateTimeOffset.Now.Add(startForDebug ?? TimeSpan.FromHours(10))) .WithSimpleSchedule(b => b.WithIntervalInHours(5)) #else .StartAt(DateTimeOffset.Now.AddMinutes(1)) .WithCronSchedule(cron, builder => builder.InTimeZone(TimeZoneInfo.Utc)) #endif ); return q; } } }