c# - Job Chaining is not executing the Jobs in sequence - Stack Overflow

I'm using Quartz.NET to schedule a series of jobs that should execute in a specific sequence.I ha

I'm using Quartz.NET to schedule a series of jobs that should execute in a specific sequence.

I have set up job chaining using JobChainingJobListener, but the jobs are not getting scheduled (thus not executed) in the order they are added to the listener, instead they are getting adding to the scheduler in random sequence.

Below is the relevant code from my QuartzScheduler class.

public class QuartzScheduler {
        public static void Configure(IServiceCollectionQuartzConfigurator q, IapConfiguration config)
        {
            q.UseDedicatedThreadPool(x => x.MaxConcurrency = 1);
            q.UsePersistentStore(x =>
            {
                x.UseProperties = true;
                x.UseClustering();
                x.UsePostgres(ReplaceParametersWithEnvVariables(config.IapDB));
                x.UseNewtonsoftJsonSerializer();
            });
            q.UseTimeZoneConverter();
        }

        public static IScheduler RegisterJobs(IScheduler scheduler, IapConfiguration config)
        {
            #region Upload Group scheduling
            var uploadGroup = "UploadGroup";

            // Create Job Keys
            JobKey uploadJobKey1 = JobKey.Create(JobConstant.Upload_IGRecChannel, uploadGroup);
            JobKey uploadJobKey2 = JobKey.Create(JobConstant.Upload_Languages, uploadGroup);
            JobKey uploadJobKey3 = JobKey.Create(JobConstant.Upload_Education, uploadGroup);
            JobKey uploadJobKey4 = JobKey.Create(JobConstant.Upload_IntWorkExp, uploadGroup);
            JobKey uploadJobKey5 = JobKey.Create(JobConstant.Upload_ExtWork, uploadGroup);
            JobKey uploadJobKey6 = JobKey.Create(JobConstant.Upload_Tagline, uploadGroup);
            JobKey uploadJobKey7 = JobKey.Create(JobConstant.IntensityJob, uploadGroup);
            JobKey uploadJobKey8 = JobKey.Create(JobConstant.AdminJob, uploadGroup);

            // Create Job Details
            IJobDetail uploadJob1 = JobBuilder.Create<JobService>()
                                       .WithIdentity(uploadJobKey1)
                                       .StoreDurably(true)
                                       .Build();

            IJobDetail uploadJob2 = JobBuilder.Create<JobService>()
                                       .WithIdentity(uploadJobKey2)
                                       .StoreDurably(true)
                                       .Build();

            IJobDetail uploadJob3 = JobBuilder.Create<JobService>()
                                       .WithIdentity(uploadJobKey3)
                                       .StoreDurably(true)
                                       .Build();

            IJobDetail uploadJob4 = JobBuilder.Create<JobService>()
                                       .WithIdentity(uploadJobKey4)
                                       .StoreDurably(true)
                                       .Build();

            IJobDetail uploadJob5 = JobBuilder.Create<JobService>()
                                       .WithIdentity(uploadJobKey5)
                                       .StoreDurably(true)
                                       .Build();

            IJobDetail uploadJob6 = JobBuilder.Create<JobService>()
                                       .WithIdentity(uploadJobKey6)
                                       .StoreDurably(true)
                                       .Build();

            IJobDetail uploadJob7 = JobBuilder.Create<JobService>()
                                       .WithIdentity(uploadJobKey7)
                                       .StoreDurably(true)
                                       .Build();

            IJobDetail uploadJob8 = JobBuilder.Create<JobService>()
                                      .WithIdentity(uploadJobKey8)
                                      .StoreDurably(true)
                                      .Build();

            // Create Trigger for the first job
            ITrigger uploadJobTrigger1 = TriggerBuilder.Create()
                                             .WithIdentity(JobConstant.Upload_IGRecChannel + "Trigger", uploadGroup)
                                             .StartNow()
                                             .Build();

            // Configure Job Listener for chaining
            JobChainingJobListener listener2 = new JobChainingJobListener("Upload  Chain");
            listener2.AddJobChainLink(uploadJobKey1, uploadJobKey2);
            listener2.AddJobChainLink(uploadJobKey2, uploadJobKey3);
            listener2.AddJobChainLink(uploadJobKey3, uploadJobKey4);
            listener2.AddJobChainLink(uploadJobKey4, uploadJobKey5);
            listener2.AddJobChainLink(uploadJobKey5, uploadJobKey6);
            listener2.AddJobChainLink(uploadJobKey6, uploadJobKey7);
            listener2.AddJobChainLink(uploadJobKey7, uploadJobKey8);

            scheduler.ListenerManager.AddJobListener(listener2, GroupMatcher<JobKey>.GroupEquals(uploadGroup));

            // Schedule and add jobs sequentially
            scheduler.ScheduleJob(uploadJob1, uploadJobTrigger1);
            scheduler.AddJob(uploadJob2, false, true);
            scheduler.AddJob(uploadJob3, false, true);
            scheduler.AddJob(uploadJob4, false, true);
            scheduler.AddJob(uploadJob5, false, true);
            scheduler.AddJob(uploadJob6, false, true);
            scheduler.AddJob(uploadJob7, false, true);
            scheduler.AddJob(uploadJob8, false, true);

            return scheduler;
            #endregion Upload Group scheduling
        }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744810064a4595004.html

相关推荐

  • c# - Job Chaining is not executing the Jobs in sequence - Stack Overflow

    I'm using Quartz.NET to schedule a series of jobs that should execute in a specific sequence.I ha

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信