该职位被引用 [英] The job referenced

查看:106
本文介绍了该职位被引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在成功调度作业时遇到了一些问题而没有得到标题中提到的错误,具体来说:触发器引用的作业(CRAWLS.my_repos)不存在。 [请参阅嵌套异常:org.quartz.JobPersistenceException:触发器引用的作业(CRAWLS.my_repos)不存在。]



这是看看代码...其中,一切看起来都应该没问题。



runJob方法......需要注意的主要问题是它失败了这一行: m_scheduler.scheduleJob(触发器); 该方法的其余部分是存在的,以防其余部分有用。

  public void runJob(JobInfo jobInfo,
com.lawson.search.spi.common.Properties jobProperties)
{
try {
JobDataMap jobDataMap = QuartzUtils.createJobDataMapFromLesProperties(jobProperties);
if(jobExists(jobInfo)){
m_scheduler.triggerJob(jobKey(jobInfo.getName(),jobInfo.getGroup()),jobDataMap);
} else {
JobDetail job = QuartzUtils.createJobDetailFromJobInfo(jobInfo);
触发器触发器= newTrigger()
.forJob(作业)
.withIdentity(getImmediateTriggerName(jobInfo))
.build();
m_scheduler.scheduleJob(触发器);
}
} catch(SchedulerException e){
String msg =runJob:+ jobInfo;
if(s_log.isDebugEnabled()){
s_log.debug(msg,e);
}
抛出新的JobSchedulerException(msg,e);
}
}

createJobDetailFromJobInfo()方法很简单,但很重要:

  static JobDetail createJobDetailFromJobInfo(JobInfo theJobInfo)
{
JobDetail detail = newJob(QuartzJobAdapter.class)
.withIdentity(theJobInfo.getName(),theJobInfo.getGroup())
.storeDurably()
.build();
返回详细信息;
}

我能想到的唯一其他重要方法是 getImmediateTriggerName()我认为可能导致问题的方法......但我不知道为什么。

  private String getImmediateTriggerName(JobInfo jobInfo)
{
return jobInfo.getName()+#+ jobInfo.getGroup()+:+ System.currentTimeMillis();
}

任何帮助都将不胜感激。

  //安排作业安排作业调试作业

触发器
m_scheduler.scheduleJob(作业,触发器);

而不是

  m_scheduler.scheduleJob(触发); 

来自 quartz-scheduler。组织



如何 - 要:在2.1.x中安排作业操作方法:安排工作在2.2.x中



两个版本的代码相同

  //定义作业实例
JobDetail job1 = newJob(ColorJob.class)
.withIdentity(job1,group1)
.build();

//定义一个现在触发的触发器,不重复
触发器触发器= newTrigger()
.withIdentity(trigger1,group1)
.startNow()
.build();

//使用触发器安排作业
sched.scheduleJob(job,trigger);

无论如何,仅当quartz无法检索 JobDetail <时才会抛出异常/ code>触发器存储期间触发器的jobkey storeTrigger 方法

  if(retrieveJob(newTrigger.getJobKey())== null){
抛出新的JobPersistenceException(作业(
+ newTrigger.getJobKey()
+)引用由触发器不存在。);
}

//添加到触发器数组
triggers.add(tw);

....

  public JobDetail retrieveJob(JobKey jobKey){
synchronized(lock){
JobWrapper jw = jobsByKey.get(jobKey);
return(jw!= null)? (JobDetail)jw.jobDetail.clone():null;
}
}

所以你的错误很奇怪,因为分配了jobkey以前 forJob 方法 TriggerBuilder

  public TriggerBuilder< T> forJob(JobDetail jobDetail){
JobKey k = jobDetail.getKey();
if(k.getName()== null)
抛出新的IllegalArgumentException(给定的作业尚未分配给它的名称。);
this.jobKey = k;
返回此;
}

尝试安排工作

  m_scheduler.scheduleJob(job,trigger); 

首先按照之前的建议,如果不起作用你应该调试代码并检查工作密钥,如果您的密钥是正确的可能问题不在您的代码中,并且是石英配置不匹配。


I'm having some trouble successfully scheduling a job without getting the error mentioned in the title, specifically: The job (CRAWLS.my_repos) referenced by the trigger does not exist. [See nested exception: org.quartz.JobPersistenceException: The job (CRAWLS.my_repos) referenced by the trigger does not exist.]

Here's a look at the code...of which, everything seems like it should be okay.

The runJob method...the main thing to notice is that it's failing in this line: m_scheduler.scheduleJob(trigger); The rest of the method is there in case the rest of it would be useful.

public void runJob(JobInfo jobInfo, 
        com.lawson.search.spi.common.Properties jobProperties)
{
    try {
        JobDataMap jobDataMap = QuartzUtils.createJobDataMapFromLesProperties(jobProperties);
        if (jobExists(jobInfo)) {
            m_scheduler.triggerJob(jobKey(jobInfo.getName(), jobInfo.getGroup()), jobDataMap);
        } else {
            JobDetail job = QuartzUtils.createJobDetailFromJobInfo(jobInfo);
            Trigger trigger = newTrigger()
                .forJob(job)
                .withIdentity(getImmediateTriggerName(jobInfo))
                .build();
            m_scheduler.scheduleJob(trigger);
        }
    } catch (SchedulerException e) {
        String msg = "runJob: " + jobInfo;
        if (s_log.isDebugEnabled()) {
            s_log.debug(msg, e);
        }
        throw new JobSchedulerException(msg, e);
    }
}

The createJobDetailFromJobInfo() method is simple, but important:

static JobDetail createJobDetailFromJobInfo(JobInfo theJobInfo)
{
  JobDetail detail = newJob(QuartzJobAdapter.class)
    .withIdentity(theJobInfo.getName(), theJobInfo.getGroup())
    .storeDurably()
    .build();
  return detail;
}

The only other important method that I can think of would be the getImmediateTriggerName() method which I think may be causing an issue...but I don't know why.

private String getImmediateTriggerName(JobInfo jobInfo)
{
    return jobInfo.getName() + "#" + jobInfo.getGroup() + ":" + System.currentTimeMillis();
}

Any help would be appreciated.

解决方案

Try scheduling a job with

// Schedule the job with the trigger 
m_scheduler.scheduleJob(job, trigger);

instead of

m_scheduler.scheduleJob(trigger);

From quartz-scheduler.org :

How-To: Scheduling a Job in 2.1.x and How-To: Scheduling a Job in 2.2.x

The code is the same for two versions

// Define job instance
JobDetail job1 = newJob(ColorJob.class)
    .withIdentity("job1", "group1")
    .build();

// Define a Trigger that will fire "now", and not repeat
Trigger trigger = newTrigger()
    .withIdentity("trigger1", "group1")
    .startNow()
    .build();

// Schedule the job with the trigger 
sched.scheduleJob(job, trigger);

Anyway, the exception is thrown only if quartz can not retrieve a JobDetail for the trigger's jobkey during the trigger store at storeTrigger method

if (retrieveJob(newTrigger.getJobKey()) == null) {
    throw new JobPersistenceException("The job ("
            + newTrigger.getJobKey()
            + ") referenced by the trigger does not exist.");
}

// add to triggers array
triggers.add(tw);

....

public JobDetail retrieveJob(JobKey jobKey) {
    synchronized(lock) {
        JobWrapper jw = jobsByKey.get(jobKey);
        return (jw != null) ? (JobDetail)jw.jobDetail.clone() : null;
    }
}

so your error is very strange because the jobkey is assigned previously at forJob method in the TriggerBuilder class

public TriggerBuilder<T> forJob(JobDetail jobDetail) {
    JobKey k = jobDetail.getKey();
    if(k.getName() == null)
        throw new IllegalArgumentException("The given job has not yet had a name assigned to it.");
    this.jobKey = k;
    return this;
}

try scheduling the job with

m_scheduler.scheduleJob(job, trigger);

first as suggested before, if does not work you should debug your code and check the job keys, if your keys are right maybe the problem is not in your code and is a quartz configuration mismatch.

这篇关于该职位被引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆