【问题标题】:Quartz.net Scheduler using clustering使用集群的 Quartz.net 调度程序
【发布时间】:2014-12-15 10:00:31
【问题描述】:

我正在使用集群选项,但我遇到了一些问题:

  1. 当我在两台机器上使用时,我创建的作业在开始时运行,与它们的定义无关。 例如:如果我将作业定义为每 10 秒运行一次,它可以在开始时每 2 秒运行一次,并且只有从第 2 次运行它是正确的 - 每 10 秒运行一次。

  2. 两台机器在同一分钟内(但不是在同一毫秒内)执行相同的作业并一起运行两次作业,我尝试使用锁定处理程序属性,但可能我没有很好地定义它。 .

这是我的代码:

NameValueCollection properties = new NameValueCollection();

properties["quartz.scheduler.instanceName"] = "TestSchedulerNECH";
properties["quartz.scheduler.instanceId"] = "instance_one";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "200";
properties["quartz.threadPool.threadPriority"] = "Normal";
properties["quartz.jobStore.misfireThreshold"] = "60000";
properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
properties["quartz.jobStore.useProperties"] = "false";
properties["quartz.jobStore.dataSource"] = "default";
properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
properties["quartz.jobStore.clustered"] = "true";
properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";
properties["quartz.dataSource.default.connectionString"] = "Server=localhost;Database=mydb;Trusted_Connection=False;User=admin;Password=123456";
properties["quartz.dataSource.default.provider"] = "SqlServer-20";


ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();

string schedId = sched.SchedulerInstanceId;

for (int i = 1; i <= 5; i++)
{

IJobDetail job = JobBuilder.Create<SimpleRecoveryJob>()
    .WithIdentity("job_" + i, schedId)
    .RequestRecovery(false)
    .Build();

ITrigger trigger = TriggerBuilder.Create()
    .StartAt(DateBuilder.FutureDate(10, IntervalUnit.Second))
    .WithCronSchedule("0/10 * * * * ? *")
    .ForJob(job)
    .EndAt(DateBuilder.FutureDate(3, IntervalUnit.Minute))
    .Build();

sched.ScheduleJob(job, trigger);
}

sched.Start();

有人可以帮助我吗?

【问题讨论】:

  • 您应该做的一个快速检查是确保两台机器上的时钟同步。
  • 两台机器上的时钟是同步的 - 这是我们检查的第一件事......不仅如此 - 我们有相同的工作在同一台机器上以不正确的间隔运行的情况。
  • 'quartz.scheduler.instanceName' 的值在所有实例上必须相同,并且每个 'quartz.scheduler.instanceId' 必须是唯一的。您的配置是否正确?
  • 是的,'quartz.scheduler.instanceName' 的值在所有实例上都是相同的,并且每个 'quartz.scheduler.instanceId' 都是唯一的

标签: c# .net quartz-scheduler quartz.net


【解决方案1】:

我知道这是一个旧线程,但是如果我们想禁止并发执行,我们必须在作业类中添加 DisallowConcurrentExecution 属性。

【讨论】:

  • 我相信这个属性只会阻止单个任务在单个机器上并行运行 - 例如计划在短时间内重复的长时间运行的任务。正如我最近所经历的那样,它不会影响或阻止两台机器(例如在负载平衡场景中)同时触发同一个作业。为此,您需要保留作业并使用唯一的机器身份,按照这些人的说明:mikaelkoskinen.net/post/quartz-net-cluster-sql-azure-asp-net
猜你喜欢
  • 1970-01-01
  • 2014-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-03
  • 1970-01-01
相关资源
最近更新 更多