Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 626
Beginner Avatar asked Mar 31 '15 11:03

Beginner


1 Answers

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.

like image 64
Max Brodin Avatar answered Sep 22 '22 10:09

Max Brodin