2

I am using the latest nuget Quartz.net packages (v2.1.2.400).

This is my job...

[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"));
    }
}

This is my job and trigger setup...

            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);

This is my config...

        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"; 

If I run a job without the [DisallowConcurrentExecution] attribute it runs as expected (i.e. every 10 seconds) like so...

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

If I run a job with the [DisallowConcurrentExecution] attribute it soon runs behind schedule like so...

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

How can I prevent concurrent execution and have my jobs run on time?

Sam Sippe
  • 3,160
  • 3
  • 27
  • 40
  • See 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 Jul 04 '13 at 08:57
  • Sorry I should have stated that I want this to work in a clustered environment so a static running property will not work. – Sam Sippe Jul 04 '13 at 21:07

1 Answers1

2

This was a bug in Quartz.NET and has been fixed in version 2.2.3. I suggest you upgrade to the latest version.

Marko Lahma
  • 6,586
  • 25
  • 29
  • Hi, I am using quartz.net 3.0.7 on .net framework 4.7.1 and experience the same behavior. Is it possible a regression was introduce as part of the 3.* release of quartz.net? – Jean-Francois Oct 12 '18 at 15:30