Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
like image 817
Luke Hutton Avatar asked Sep 14 '15 21:09

Luke Hutton


1 Answers

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.

like image 99
Evk Avatar answered Nov 19 '22 23:11

Evk