Quartz.NET scheduler.Interrupt(jobKey) is interrupting all active jobs

微笑、不失礼 提交于 2019-12-23 07:51:47

问题


Should the method only interrupt the job as defined by the jobKey? I've ran some tests and it seems to interrupt all of the active jobs currently running.

I am using a restful web api to connect to the remote scheduler to create/interrupt/delete jobs.

Api service code:

public void DeleteJob(JobKey jobKey)
{
    var scheduler = _clientQuartzScheduler.GetScheduler();

    var executingJobs = scheduler.GetCurrentlyExecutingJobs();

    if (executingJobs.Any(x => x.JobDetail.Key.Equals(jobKey)))
    {
        scheduler.Interrupt(jobKey);
    }

    scheduler.DeleteJob(jobKey);
}

Quartz remote scheduler app settings are:

<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="Normal" />

<add key="quartz.scheduler.exporter.type" value="Quartz.Simpl.RemotingSchedulerExporter, Quartz" />
<add key="quartz.scheduler.exporter.port" value="555" />
<add key="quartz.scheduler.exporter.bindName" value="QuartzScheduler" />
<add key="quartz.scheduler.exporter.channelType" value="tcp" />
<add key="quartz.scheduler.exporter.channelName" value="httpQuartz" />
<add key="quartz.scheduler.exporter.rejectRemoteRequests" value="false" />

<add key="quartz.jobStore.clustered" value="false" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
<add key="quartz.jobStore.useProperties" value="true" />
<add key="quartz.jobStore.dataSource" value="default" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz" />   

<add key="quartz.dataSource.default.provider" value="MySql-65" />
<add key="quartz.dataSource.default.connectionStringName" value="DatabaseConnectionString" />

The api client settings are:

properties["quartz.scheduler.instanceName"] = "RemoteClient";
properties["quartz.scheduler.proxy"] = "true";
properties["quartz.threadPool.threadCount"] = "0";
properties["quartz.scheduler.proxy.address"] = address;

回答1:


To answer such questions it's easier to just look at source code of method in question (if possible). If you look at source code for Interrupt, you will see approximately this:

public virtual bool Interrupt(JobKey jobKey)
{
  var currentlyExecutingJobs = this.CurrentlyExecutingJobs;
  bool interruptedAny = false;
  foreach (var executionContext in currentlyExecutingJobs)
  {
    var jobDetail = executionContext.JobDetail;
    if (jobKey.Equals((object) jobDetail.Key))
    {
      var interruptableJob = executionContext.JobInstance as IInterruptableJob;
        if (interruptableJob != null) {
            interruptableJob.Interrupt();
            interruptedAny = true;
        }
        else {
            // throws here
        }
    }
  }
  return interruptedAny;
}

So it enumerates all current jobs and interrupts any with the matching JobKey (which by the way makes checks in your code unnecessary - you can just do scheduler.Interrupt(jobKey)). So unless all your jobs somehow have matching key - it should not delete them all.




回答2:


I apologize but I finally found the issue on my end. It turned out to be a misconfiguration with my registration code using a NInjectJobFactory.

Basically, there was only a single job instance running for each job execution so the flag I was setting to stop the job being interrupted was shared amongst all job executions, thereby stopping all the jobs!



来源:https://stackoverflow.com/questions/32573853/quartz-net-scheduler-interruptjobkey-is-interrupting-all-active-jobs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!