防止Quartz作业恢复从长期运行任务开始

时间:2015-10-05 06:35:51

标签: quartz-scheduler quartz.net

我在设置RequestRecovery标志的情况下构建Quartz作业,因为我有多个服务器实例正在运行,如果在运行作业时失败,我想要另一个实例来获取该作业并重新启动它。

IJobDetail job = JobBuilder.Create<SystemMaintenance>()
                .WithIdentity("SystemMaintenance", "SystemMaintenance")
               .RequestRecovery(true)                   
               .WithDescription("System task that runs every 6 hours")
               .Build();

然而,我注意到的是,如果作业运行了很长时间(例如超过10分钟),其他实例将开始运行该作业,因为他们认为它已经失败,即使它运行正常。

有没有办法可以定期ping Quartz,可能通过JobExecutionContext,让它知道某个特定实例仍在运行并处理作业,以防止其他人假设失败并启动它?

修改

我的配置如下:

        NameValueCollection properties = new NameValueCollection();

        properties["quartz.scheduler.instanceName"] = "Scheduler";
        properties["quartz.scheduler.instanceId"] = "AUTO";
        properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
        properties["quartz.threadPool.threadCount"] = "5";
        properties["quartz.threadPool.threadPriority"] = "Normal";
        properties["quartz.jobStore.misfireThreshold"] = "60000";

        properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
        properties["quartz.jobStore.useProperties"] = "true";
        properties["quartz.jobStore.dataSource"] = "default";
        properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
        properties["quartz.jobStore.clustered"] = "true";
        properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";
        properties["quartz.dataSource.default.connectionString"] = ConnectionStringService.DatabaseConnectionString;
        properties["quartz.dataSource.default.provider"] = "SqlServer-20";

0 个答案:

没有答案