Используемая версия:
Код: Выделить всё
Код: Выделить всё
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddQuartz();
builder.Services.AddQuartzHostedService(opt =>
{
opt.WaitForJobsToComplete = true;
});
builder.Services.ConfigureOptions();
builder.Services.AddScoped();
Код: Выделить всё
public class BackgroundJobTemporarilyRefusedSetup(
IServiceScopeFactory serviceScopeFactory) : IConfigureOptions
{
public async void Configure(QuartzOptions options)
{
var jobKeyTemporarilyRefused = BackgroundJobTemporarilyRefused.Key;
using var scope = serviceScopeFactory.CreateScope();
var backgroundProcessSettingRepository = scope.ServiceProvider.GetRequiredService();
var backgroundProcessSettingExists = await backgroundProcessSettingRepository.Exists(jobKeyTemporarilyRefused.Name);
if (!backgroundProcessSettingExists)
throw new Exception($"Can`t find setting with JobKeyName = {jobKeyTemporarilyRefused.Name}");
// Get cron expression from DB
var backgroundProcessSetting = await backgroundProcessSettingRepository
.GetBackgroundProcessSettingAppModelByJobKeyName(jobKeyTemporarilyRefused.Name);
options
.AddJob(jobBuilder => jobBuilder.WithIdentity(jobKeyTemporarilyRefused))
.AddTrigger(trigger =>
trigger
.ForJob(jobKeyTemporarilyRefused)
.WithCronSchedule(backgroundProcessSetting.CronScheduleString,
x => x.WithMisfireHandlingInstructionDoNothing()));
}
}
Код: Выделить всё
[DisallowConcurrentExecution]
public class BackgroundJobTemporarilyRefused(
IUserTemporarilyRefusedFromMeetingHandleService userTemporarilyRefusedFromMeetingHandleService,
ILogger logger) : IJob
{
public static readonly JobKey Key = JobKey.Create(nameof(BackgroundJobTemporarilyRefused));
public async Task Execute(IJobExecutionContext context)
{
try
{
await userTemporarilyRefusedFromMeetingHandleService.UserTemporarilyRefusedFromMeetingHandle();
}
catch (Exception e)
{
logger.CustomError(e);
}
}
}
Cron-выражение из БД получено корректно.
Почему триггер добавлен некорректно? Помогите пожалуйста.
Я попробовал добавить группу для триггеров:
Код: Выделить всё
.WithIdentity("Trigger", "TestGroup")
Код: Выделить всё
opt.WaitForJobsToComplete = true;
opt.AwaitApplicationStarted = true;
Подробнее здесь: https://stackoverflow.com/questions/791 ... cation-sta