add quartz for jobs

configure auto-scan folder and create hls files job WIP
This commit is contained in:
Oleksandr Bezdieniezhnykh
2024-07-26 14:11:29 +03:00
parent 5e55210eac
commit 7807f5bc90
18 changed files with 179 additions and 28 deletions
@@ -0,0 +1,27 @@
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;
}
}
}