该方法是否只会中断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;
答案 0 :(得分:3)
要回答这些问题,只需查看相关方法的源代码(如果可能)就更容易了。如果你查看中断的源代码,你会看到大约这个:
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();
flag = true;
}
else {
// throws here
}
}
}
return interruptedAny;
}
因此,它使用匹配的JobKey枚举所有当前作业并中断任何内容(顺便说一句,这样就不需要对代码进行检查 - 您只需执行scheduler.Interrupt(jobKey))。因此,除非您的所有工作都以某种方式具有匹配的密钥 - 它不应该全部删除它们。
答案 1 :(得分:0)
我道歉但最后我终于找到了问题。事实证明,使用NInjectJobFactory
对我的注册码进行了错误配置。
基本上,每个作业执行只运行一个作业实例,因此我设置的停止作业被中断的标志在所有作业执行中共享,从而停止所有作业!