Files
annotations/Web/Azaion.Web/Azaion.Repository/Extensions/QuartzJobConfigHelper.cs
T
Oleksandr Bezdieniezhnykh 7807f5bc90 add quartz for jobs
configure auto-scan folder and create hls files job WIP
2024-07-26 14:11:29 +03:00

27 lines
966 B
C#

using Azaion.Repository.Jobs;
using Quartz;
namespace Azaion.Repository.Extensions
{
public static class QuartzJobConfigHelper
{
public static IServiceCollectionQuartzConfigurator RegisterJob<T>(this IServiceCollectionQuartzConfigurator q,
string cron, TimeSpan? startForDebug = null) where T: BaseJob
{
var jobName = typeof(T).Name;
var jobKey = new JobKey(jobName);
q.AddJob<T>(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;
}
}
}