2013-07-04 110 views
2

我正在使用最新的nuget Quartz.net軟件包(v2.1.2.400)。Quartz.net使用DisallowConcurrentExecution後執行

這是我的工作......

[DisallowConcurrentExecution] 
[PersistJobDataAfterExecution] 
public class HelloJob : IJob 
{ 
    public void Execute(IJobExecutionContext context) 
    { 
     Console.Out.WriteLine("Hello Job Now=" + DateTime.Now.ToString("s") + " Next=" + context.NextFireTimeUtc.Value.ToLocalTime().ToString("s")); 
    } 
} 

這是我的工作,觸發設置...

  trigger = TriggerBuilder.Create() 
      .WithIdentity("trigger1") 
      .StartAt(DateTime.UtcNow.AddSeconds(5)) 
      .WithSchedule(SimpleScheduleBuilder 
       .RepeatSecondlyForever(10) 
       .WithMisfireHandlingInstructionIgnoreMisfires()      
      ).Build(); 
      var job = JobBuilder.Create<HelloJob>().WithIdentity("job1").Build(); 
      sched.ScheduleJob(job, trigger); 

這是我的配置...

 properties["quartz.scheduler.instanceName"] = "TestScheduler"; 
     properties["quartz.scheduler.instanceId"] = "AUTO"; 
     properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"; 
     properties["quartz.jobStore.useProperties"] = "true"; 
     properties["quartz.jobStore.dataSource"] = "default"; 
     properties["quartz.jobStore.tablePrefix"] = "QRTZ_"; 
     // if running MS SQL Server we need this 
     properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz"; 
     properties["quartz.jobStore.clustered"] = "true"; 

     //http://www.connectionstrings.com/mysql#mysql-connector-net-mysqlconnection 
     properties["quartz.dataSource.default.connectionString"] = "Server=localhost;Database=quartz;Uid=xxxx;Pwd=xxxxxx;"; 
     properties["quartz.dataSource.default.provider"] = "MySql-65"; 

如果我運行一個沒有[DisallowConcurrentExecution]屬性的作業,它像預期的那樣運行(即每10秒)...

Hello Job Now=2013-07-04T13:04:16 Next=2013-07-04T13:04:26 
Hello Job Now=2013-07-04T13:04:26 Next=2013-07-04T13:04:36 
Hello Job Now=2013-07-04T13:04:36 Next=2013-07-04T13:04:46 
Hello Job Now=2013-07-04T13:04:46 Next=2013-07-04T13:04:56 
Hello Job Now=2013-07-04T13:04:56 Next=2013-07-04T13:05:06 

如果我運行與[DisallowConcurrentExecution]任務屬性它很快就慢了,像這樣的時間表......

Hello Job Now=2013-07-04T13:11:00 Next=2013-07-04T13:11:10 
Hello Job Now=2013-07-04T13:11:10 Next=2013-07-04T13:11:20 
Hello Job Now=2013-07-04T13:11:47 Next=2013-07-04T13:11:30 
Hello Job Now=2013-07-04T13:12:17 Next=2013-07-04T13:11:40 

如何防止併發執行,並有我的工作時間運行?

+0

查看http://stackoverflow.com/questions/16520645/how-to-create-quartz-job-that-will-runs-every-n-seconds-even-if-job-takes-more-t/ 16525197#16525197 – sgmoore

+0

對不起,我應該說,我希望這在集羣環境中工作,所以靜態運行屬性將無法正常工作。 –

回答

2

這是Quartz.NET中的一個bug,已經在2.2.3版本中修復。我建議你升級到最新版本。