From 914b129e4980700c6abc51e5879dca5fc9b58038 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Sat, 9 Apr 2022 17:25:18 +0800 Subject: [PATCH] fix: fix throw Quartz.SchedulerException: Repeat Interval cannot be zero. --- .../Quartz/QuartzJobExecutorProvider.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobExecutorProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobExecutorProvider.cs index b05185607..eb0cf3ca5 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobExecutorProvider.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobExecutorProvider.cs @@ -122,10 +122,19 @@ public class QuartzJobExecutorProvider : IQuartzJobExecutorProvider, ISingletonD .StartAt(Clock.Now.AddSeconds(job.Interval)) .EndAt(job.EndTime) .ForJob(KeyBuilder.CreateJobKey(job)) - .WithPriority((int)job.Priority) - .WithSimpleSchedule(x => - x.WithIntervalInSeconds(job.Interval) - .WithRepeatCount(maxCount)); + .WithPriority((int)job.Priority); + + // Quartz约定. 重复间隔不能为0 + // fix throw Quartz.SchedulerException: Repeat Interval cannot be zero. + var scheduleBuilder = SimpleScheduleBuilder.Create(); + scheduleBuilder.WithRepeatCount(maxCount); + if (job.Interval > 0) + { + scheduleBuilder.WithIntervalInSeconds(job.Interval); + } + + triggerBuilder.WithSchedule(scheduleBuilder); + break; }