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

3

8

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.

Sedentary answered 30/3, 2015 at 3:17 Comment(0)
G
3

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();
Gleet answered 30/3, 2015 at 9:53 Comment(1)
This is invalid code. You can't specify two different kinds of schedule (daily and calendar here).Gourley
P
1

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

Peculation answered 30/3, 2015 at 21:0 Comment(0)
T
0

Use the following expression to schedule a job to run on alternate Mondays and tuesdays.

0 0 0 1-7,15-21,29-31 * 1,2 *

Here is how the expression is described.

0 -- 0th sec

0 -- 0th min

0 -- 0th hr

1-7,15-21,29-31 -- on alternate week of the month

  • -- any month

1,2 -- On Monday and Tuesday

  • -- Any year.
Tropophilous answered 30/3, 2015 at 9:18 Comment(2)
Cronmaker.com says this expression is invalid. Please helpSedentary
Shetty87 Could you post a full example of a quartz cron job ?Woosley

© 2022 - 2024 — McMap. All rights reserved.