Quartz.NET scheduler.Interrupt(jobKey) 正在中断所有活动作业
Quartz.NET scheduler.Interrupt(jobKey) is interrupting all active jobs
该方法是否应该只中断由 jobKey 定义的作业?我已经 运行 进行了一些测试,它似乎中断了当前 运行.
所有的活动作业
我正在使用 restful 网络 api 连接到远程调度程序以执行 create/interrupt/delete 作业。
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))。因此,除非您的所有作业都以某种方式具有匹配的密钥 - 它不应该将它们全部删除。
我很抱歉,但我终于找到了我这边的问题。结果证明是我的注册码配置错误,使用 NInjectJobFactory
。
基本上,每个作业执行只有一个作业实例 运行,所以我设置的停止作业被中断的标志在所有作业执行之间共享,从而停止所有作业!
该方法是否应该只中断由 jobKey 定义的作业?我已经 运行 进行了一些测试,它似乎中断了当前 运行.
所有的活动作业我正在使用 restful 网络 api 连接到远程调度程序以执行 create/interrupt/delete 作业。
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))。因此,除非您的所有作业都以某种方式具有匹配的密钥 - 它不应该将它们全部删除。
我很抱歉,但我终于找到了我这边的问题。结果证明是我的注册码配置错误,使用 NInjectJobFactory
。
基本上,每个作业执行只有一个作业实例 运行,所以我设置的停止作业被中断的标志在所有作业执行之间共享,从而停止所有作业!