【问题标题】:Quartz.net Late Execution with DisallowConcurrentExecutionQuartz.net 延迟执行与 DisallowConcurrentExecution
【发布时间】:2013-07-04 03:17:21
【问题描述】:

我正在使用最新的 nuget Quartz.net 软件包 (v2.1.2.400)。

这是我的工作……

[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

如何防止并发执行并让我的作业按时运行?

【问题讨论】:

标签: quartz.net quartz.net-2.0


【解决方案1】:

这是 Quartz.NET 中的一个错误,已在 2.2.3 版中修复。我建议你升级到最新版本。

【讨论】:

  • 嗨,我在 .net 框架 4.7.1 上使用quartz.net 3.0.7 并遇到相同的行为。是否有可能在quartz.net 3.* 版本中引入回归?
猜你喜欢
  • 2022-12-27
  • 2011-01-25
  • 2018-02-25
  • 2011-09-23
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多