feat(EnvelopeGenerator.Finalizer.Win): Create to process window-oriented services
This commit is contained in:
35
EnvelopeGenerator.Finalizer.Win/Extensions.cs
Normal file
35
EnvelopeGenerator.Finalizer.Win/Extensions.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using EnvelopeGenerator.Finalizer.Job;
|
||||
using Quartz;
|
||||
|
||||
namespace EnvelopeGenerator.Finalizer;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static IServiceCollectionQuartzConfigurator ScheduleJobDefault<TJob>(this IServiceCollectionQuartzConfigurator q,
|
||||
string croneEpression)
|
||||
where TJob : IJob
|
||||
{
|
||||
var name = $"{typeof(TJob).FullName}";
|
||||
var jobKey = new JobKey(name);
|
||||
|
||||
return q.ScheduleJob<TJob>(trigger => trigger
|
||||
.WithIdentity(name + "-trigger")
|
||||
.WithCronSchedule(croneEpression),
|
||||
job => job.WithIdentity(jobKey)
|
||||
);
|
||||
}
|
||||
|
||||
public static IServiceCollectionQuartzConfigurator ScheduleJobDefault<TJob>(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<TJob>(expression);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user