简体   繁体   中英

How to chain more than 2 jobs using JobChainingJobListener Quartz.net?

I want to chain the 3 jobs, but AddJobChainLink() gets only 2 jobKeys as parameter.

scheduler = container.GetInstance<IScheduler>();
            scheduler.JobFactory = container.GetInstance<IJobFactory>();    JobKey jobkey1 = new JobKey("job1", "group1");
            JobKey jobkey2 = new JobKey("job2", "group2");
            JobKey jobkey3 = new JobKey("job3", "group3");

            var job1 = JobBuilder.Create<Type1>().WithIdentity("job1", "group1").Build();
            var job2 = JobBuilder.Create<Type2>().WithIdentity("job2", "group2").Build();
            var job3 = JobBuilder.Create<Type3>().WithIdentity("job3", "group3").Build();

            ITrigger trigger1 = TriggerBuilder.Create().WithIdentity("trigger1", "group1").StartNow().Build();

            JobChainingJobListener chain = new JobChainingJobListener("testChain");
            chain.AddJobChainLink(jobkey1, jobkey2);
            scheduler.ScheduleJob(job1, trigger1);
            scheduler.AddJob(job2, true);
            scheduler.AddJob(job3, true);

            scheduler.ListenerManager.AddJobListener(chain, GroupMatcher<JobKey>.AnyGroup());

            scheduler.Start();

Try this:

JobChainingJobListener chain = new JobChainingJobListener("testChain");
chain.AddJobChainLink(jobkey1, jobkey2);
chain.AddJobChainLink(jobkey2, jobkey3);

JobChainingJobListener helps you create a chain of execution for your jobs in a specific order you desire. You just need to chain each job with another in specific order.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM