Quartz.NET Scheduler.Interrupt(jobKey) 正在中断所有活动作业

2023-12-29

该方法是否应该只中断 jobKey 定义的作业?我已经运行了一些测试,它似乎中断了当前正在运行的所有活动作业。

我正在使用 Restful Web api 连接到远程调度程序以创建/中断/删除作业。

API服务代码:

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 远程调度程序应用程序设置为:

<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" />

api 客户端设置为:

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

要回答此类问题,只需查看相关方法的源代码(如果可能)会更容易。如果您查看中断的源代码,您将大致看到以下内容:

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;
}

因此,它枚举所有当前作业并使用匹配的 JobKey 中断任何作业(顺便说一句,这使得无需检查代码 - 您只需执行 Scheduler.Interrupt(jobKey) 即可)。因此,除非您的所有作业都以某种方式具有匹配的密钥 - 它不应该将它们全部删除。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Quartz.NET Scheduler.Interrupt(jobKey) 正在中断所有活动作业 的相关文章

随机推荐