using EnvelopeGenerator.Finalizer.Job; using Quartz; namespace EnvelopeGenerator.Finalizer; public static class Extensions { public static IServiceCollectionQuartzConfigurator ScheduleJobDefault(this IServiceCollectionQuartzConfigurator q, string croneEpression) where TJob : IJob { var name = $"{typeof(TJob).FullName}"; var jobKey = new JobKey(name); return q.ScheduleJob(trigger => trigger .WithIdentity(name + "-trigger") .WithCronSchedule(croneEpression), job => job.WithIdentity(jobKey) ); } public static IServiceCollectionQuartzConfigurator ScheduleJobDefault(this IServiceCollectionQuartzConfigurator q, IConfiguration configuration) where TJob : IJob { var expression = configuration[$"{typeof(TJob).Name}:CronExpression"]; if (string.IsNullOrWhiteSpace(expression)) throw new InvalidOperationException( "Cron expression for the Worker job is not configured. " + "Please provide a valid cron schedule in the configuration under " + $"'{typeof(TJob).FullName}:CronExpression'."); return q.ScheduleJobDefault(expression); } }