From 124281dc786de8d98d279ac13f99c0f570034328 Mon Sep 17 00:00:00 2001 From: dongfo <630024306@qq.com> Date: Tue, 12 May 2026 15:57:46 +0800 Subject: [PATCH] Update QuartzJobCreator.cs --- .../Quartz/QuartzJobCreator.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs index 91e40d67b..43f82c739 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs @@ -125,11 +125,21 @@ public class QuartzJobCreator : IQuartzJobCreator, ISingletonDependency triggerBuilder .WithIdentity(KeyBuilder.CreateTriggerKey(job)) .WithDescription(job.Description) - .StartAt(Clock.Now.AddSeconds(job.Interval)) .EndAt(job.EndTime) .ForJob(KeyBuilder.CreateJobKey(job)) .WithPriority((int)job.Priority); - + + // 首次启动时间由 BeginTime 决定,不再使用 Interval 作为"延迟启动"。 + // Interval 仅在 Persistent 周期任务中表示"重复间隔"。 + if (job.BeginTime > Clock.Now) + { + triggerBuilder.StartAt(job.BeginTime); + } + else + { + triggerBuilder.StartNow(); + } + // Quartz约定. 重复间隔不能为0 // fix throw Quartz.SchedulerException: Repeat Interval cannot be zero. var scheduleBuilder = SimpleScheduleBuilder.Create(); @@ -139,14 +149,8 @@ public class QuartzJobCreator : IQuartzJobCreator, ISingletonDependency { scheduleBuilder.WithRepeatCount(maxCount); } - if (job.Interval > 0) - { - scheduleBuilder.WithIntervalInSeconds(job.Interval); - } - else - { - scheduleBuilder.WithIntervalInSeconds(300); - } + scheduleBuilder.WithIntervalInSeconds(job.Interval > 0 ? job.Interval : 300); + triggerBuilder.WithSchedule(scheduleBuilder);