Код: Выделить всё
public static class QuartzConfiguration
{
public static void AddQuartzConfiguration(this WebApplicationBuilder builder)
{
var serviceProvider = builder.Services.BuildServiceProvider();
var notificationCronExpression = serviceProvider.GetService();
var checkTaskStatusCronExpression = serviceProvider.GetService();
var legislativeCronExpression = serviceProvider.GetService();
var payRunTasksToAutoCompleteCronExpression = serviceProvider.GetService();
builder.Services.AddQuartz(quartzConfigurator =>
{
quartzConfigurator.UseJobAutoInterrupt(options => options.DefaultMaxRunTime = TimeSpan.FromMinutes(10));
quartzConfigurator.UseDefaultThreadPool(maxConcurrency: 1);
quartzConfigurator.UseTimeZoneConverter();
quartzConfigurator.UsePersistentStore(store =>
{
store.UseNewtonsoftJsonSerializer();
});
quartzConfigurator.AddQuartzJob(checkTaskStatusCronExpression.Value.Value, "CheckTaskStatus", "Test", "CheckTaskStatusTrigger", "GenerateTaskStatusPollerFactory");
quartzConfigurator.AddQuartzJob(notificationCronExpression.Value.Value, "GenerateNotifications", "Test", "GenerateNotificationsTrigger", "GenerateNotificationsPollerFactory");
quartzConfigurator.AddQuartzJob(legislativeCronExpression.Value.Value, "PollLegislativeUpdates", "Test", "PollLegislativeUpdatesTrigger", "LegislativeUpdatePollerFactory");
quartzConfigurator.AddQuartzJob(payRunTasksToAutoCompleteCronExpression.Value.Value, "AutoCompletePayRunTasks", "Test", "AutoCompletePayRunTasksTrigger", "PayRunTaskStatusPollerFactory");
});
builder.Services.AddQuartzServer(options =>
{
// when shutting down we want jobs to complete gracefully
options.WaitForJobsToComplete = true;
});
}
Код: Выделить всё
public static class QuartzConfiguratorExtensions
{
public static void AddQuartzJob(this IServiceCollectionQuartzConfigurator quartzConfigurator,
string cronExpression,
string key, string group,
string triggerName, string triggerGroup) where T: IJob
{
bool isCronExpressionValid = CronExpression.IsValidExpression(cronExpression);
if(!isCronExpressionValid)
{
throw new Exception ($"{cronExpression} is not a valid cron expression for Quartz job {key}");
}
quartzConfigurator.AddJob(jobConfigurator => jobConfigurator.WithIdentity(key, group));
quartzConfigurator.AddTrigger(triggerConfigurator => triggerConfigurator
.ForJob(key)
.WithIdentity(triggerName, triggerGroup)
.WithCronSchedule(cronExpression));
}
}
Код: Выделить всё
app.Run();
Имя источника данных не задано
Трассировка стека:
Код: Выделить всё
at Quartz.Impl.AdoJobStore.JobStoreSupport.d__143.MoveNext()
at Quartz.Impl.AdoJobStore.JobStoreTX.d__0.MoveNext()
at Quartz.Impl.StdSchedulerFactory.d__67.MoveNext()
at Quartz.Impl.StdSchedulerFactory.d__67.MoveNext()
at Quartz.Impl.StdSchedulerFactory.d__73.MoveNext()
at Quartz.ServiceCollectionSchedulerFactory.d__6.MoveNext()
at Quartz.QuartzHostedService.d__7.MoveNext()
at Microsoft.Extensions.Hosting.Internal.Host.d.MoveNext()
at Microsoft.Extensions.Hosting.Internal.Host.d__18`1.MoveNext()
at Microsoft.Extensions.Hosting.Internal.Host.d__15.MoveNext()
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.d__4.MoveNext()
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.d__4.MoveNext()
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at Program.$(String[] args) in C:\_PROJECTS_\PPM\IIPay.PPM.Api\Program.cs:line 62
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/786 ... me-not-set