Quartz.NET ScheduledFireTimeUtc 當超過1分鐘時出現的問題。

驗證代碼:ui

 1     class Program
 2     {
 3         public static IScheduler scheduler = null;
 4         static void Main(string[] args)
 5         {
 6             scheduler = StdSchedulerFactory.GetDefaultScheduler();
 7             scheduler.Start();
 8             string GroupName = "DateRules";
 9             string RunCorn = "0 " + DateTime.Now.AddMinutes(1).Minute + " * * * ?";
10             for (int i = 0; i < 30; i++)
11             {
12                 string Identity = "DataRule_" + i;
13 
14                 JobDataMap JobData = new JobDataMap();
15                 JobData["Index"] = i;
16                 IJobDetail job = JobBuilder.Create<MyJob>()
17                    .WithIdentity(Identity, GroupName)
18                    .SetJobData(JobData)
19                    .Build();
20 
21                 ITrigger trigger = TriggerBuilder.Create()
22                     .WithIdentity(Identity, Identity)
23                     .WithCronSchedule(RunCorn)
24                     .Build();
25 
26                 scheduler.ScheduleJob(job, trigger);
27             }
28             Console.ReadLine();
29         }
    public class MyJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            var FireTimeAfter = context.Trigger.GetFireTimeAfter(context.ScheduledFireTimeUtc.Value.ToLocalTime());
        
string Index = context.JobDetail.JobDataMap["Index"].ToString(); Thread.Sleep(30000); Console.WriteLine( FireTimeAfter.Value.ToLocalTime() + "\t" + context.ScheduledFireTimeUtc.Value.ToLocalTime() + "\t" + Index); } }

quartz自己包含一個線程池,讓線程池中全部線程都Sleep30秒後輸出ScheduledFireTimeUtc爲示例:2019-09-17 09:00:00 ,當Sleep超過1分鐘再啓動的Job的ScheduledFireTimeUtc變爲了:2019-09-17 09:01:00 spa

這時使用使用GetFireTimeAfter從新取得應執行時間。線程

相關文章
相關標籤/搜索