简体   繁体   中英

QUARTZ.NET chain crone jobs

In my Net5 application, I tried to implement Quartz crone jobs but with synchronous implementation.I want every job to wait for the previous one to finish. After a lot of examples and mistakes, I found this solution LINK because a read that the only way to make jobs runs synchronously is to chain them. But also I need these jobs to start each Sunday and I tried with crone job. The problem is if I use to trigger with crone only the first job was fired. How to refactor example to run with a cron job or every Sunday.I made some changes to the trigger:

 ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("Trigger", "Update All")
                .WithSchedule(CronScheduleBuilder
                    .WeeklyOnDayAndHourAndMinute(DayOfWeek.Sunday, 12, 04)
                    .InTimeZone(TimeZoneInfo.Utc)
                    .WithMisfireHandlingInstructionFireAndProceed())
                 .StartNow()
                 .Build();

I found the solution. First, removed chaining and add only one thread for the scheduler.Also, I put attribute [DisallowConcurrentExecution] for every job and use WithPriority().

Another possible option is to pass in the name of the job that needs to run after the first job, and then actually schedule the second job at the end of the first job. So you schedule your first job, then when the first job finishes it's task it schedules the second job... and so on.

The Execute method of the IJob interface includes an IJobExecutionContext object that gets passed to the job as a method parameter. The IJobExecutionContext includes a reference to the Scheduler which you can use to schedule the next job. You can use the IJobExecutionContext.JobDetail.JobDataMap reference to pass in data (such as the information for the next job) to the job.

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