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

时间秒杀一切 提交于 2019-12-01 17:21:04

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();

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

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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!