使用JobChainingJobListener乔布斯没有链接 [英] Jobs not chaining using JobChainingJobListener
问题描述
我目前的代码为我的Quartz调度:
I have the current code for my Quartz scheduler:
var scheduler = StdSchedulerFactory.GetDefaultScheduler();
// Job1
var Job1 = JobBuilder.Create<Test1>().WithIdentity("job1", "group1").Build();
// Job2
var Job2 = JobBuilder.Create<Test2>().WithIdentity("job2", "group2").Build();
// Triggers
ITrigger trigger1 = TriggerBuilder.Create().WithIdentity("trigger1", "group1").StartNow().Build()
ITrigger trigger2 = TriggerBuilder.Create().WithIdentity("trigger2", "group2").StartNow().WithSimpleSchedule(x => x.WithIntervalInSeconds(1).WithRepeatCount(4)).Build();
// JobKeys
JobKey jobKey1 = new JobKey("Job1", "group1");
JobKey jobKey2 = new JobKey("Job2", "group2");
// Chain jobs
JobChainingJobListener chain = new JobChainingJobListener("testChain");
chain.AddJobChainLink(jobKey1, jobKey2);
scheduler.ScheduleJob(Job1, trigger1);
scheduler.AddJob(Job2, true);
// Global listener here. I am not sure what I have is correct.
scheduler.ListenerManager.AddJobListener(chain, GroupMatcher<JobKey>.AnyGroup());`
scheduler.Start();
(为了澄清,工作做的无非就是印刷更多的时刻来安慰。)
(For clarification, the jobs do nothing more than print to console at the moment.)
从石英网站,我发现,这将增加一个JobListener是感兴趣的所有作业: scheduler.ListenerManager.AddJobListener(链,GroupMatcher< JobKey> .AnyGroup());
我不知道,这相当于全球听众
From the Quartz website, I found that this will add a JobListener that is interested in all jobs: scheduler.ListenerManager.AddJobListener(chain, GroupMatcher<JobKey>.AnyGroup());
I'm not sure that this is equivalent to a global listener.
我还发现,一些代码里的人在Java中;做了 scheduler.addGlobalJobListener(链)。有没有在C#等效方法?
I also found that some code where people have done scheduler.addGlobalJobListener(chain);
in Java. Is there an equivalent method in c#?
我的代码编译,似乎没有错误运行,但JOB2不会触发。作业1正确打印到控制台。
My code compiles and seems to run without errors, but Job2 does not trigger. Job1 prints properly to console.
推荐答案
这里的问题是,你有拼写错误的关键,第二次(作业1与 JOB1),这将导致那里是没有已知的链接触发。下面是去掉冗余更新的代码示例。
The issue here is that you have misspelled the key the second time ("Job1" vs "job1") which causes there to be no known link to fire. Here's updated code sample with redundancies removed.
var scheduler = StdSchedulerFactory.GetDefaultScheduler();
JobKey jobKey1 = new JobKey("job1", "group1");
JobKey jobKey2 = new JobKey("job2", "group2");
var job1 = JobBuilder.Create<Test1>().WithIdentity(jobKey1).Build();
var job2 = JobBuilder.Create<Test2>().WithIdentity(jobKey2).StoreDurably(true).Build();
ITrigger trigger1 = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartNow()
.Build();
JobChainingJobListener chain = new JobChainingJobListener("testChain");
chain.AddJobChainLink(jobKey1, jobKey2);
scheduler.ListenerManager.AddJobListener(chain, GroupMatcher<JobKey>.AnyGroup());
scheduler.ScheduleJob(job1, trigger1);
scheduler.AddJob(job2, true);
scheduler.Start();
的
scheduler.addGlobalJobListener
是旧的API和2.X系列较长的一部分。您应该使用像ListenerManager你做了。
The scheduler.addGlobalJobListener
is old API and longer part of 2.x series. You should use the ListenerManager like you have done.
这篇关于使用JobChainingJobListener乔布斯没有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!