Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a quartz schedule on mondays and tuesdays every two weeks?

I used the below way to run the schedule on every two weeks on mondays.

ITrigger trigger = TriggerBuilder.Create()
                                    .StartAt(DateBuilder.DateOf(StartHour, StartMinute, StartSeconds, StartDate, StartMonth, StartYear))
                                    .WithCalendarIntervalSchedule(x => x.WithIntervalInWeeks(Int32.Parse(nWeekInterval)))
                                    .EndAt(DateBuilder.DateOf(0, 0, 0, EndDay, EndMonth, EndYear))
                                    .Build();

But how can I use a single schedule to run on mondays and tuesdays as well. Please advice.

like image 455
Kalpa-W Avatar asked Mar 30 '15 03:03

Kalpa-W


2 Answers

You can specify days of the week with DailyTimeIntervalScheduleBuilder

var onMondayAndTuesday = DailyTimeIntervalScheduleBuilder.Create()
                         .OnDaysOfTheWeek(new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday });

var trigger = TriggerBuilder.Create()
                            .StartAt(DateBuilder.DateOf(StartHour, StartMinute, StartSeconds, StartDate, StartMonth, StartYear))
                            .WithSchedule(onMondayAndTuesday)
                            .WithCalendarIntervalSchedule(x => x.WithIntervalInWeeks(Int32.Parse(nWeekInterval)))
                            .EndAt(DateBuilder.DateOf(0, 0, 0, EndDay, EndMonth, EndYear))
                            .WithIdentity(triggerKey)
                            .Build();
like image 110
Nick Patsaris Avatar answered Sep 21 '22 17:09

Nick Patsaris


I would create one job with two different triggers. Each trigger fires biweekly (or semi-monthly).

like image 34
mg3 Avatar answered Sep 25 '22 17:09

mg3