Quartz.Net - Every 3 weeks on Mon,Tue,Wed

2019-06-17 09:57发布

I'm stuck with Quartz.NET cron trigger. I was able to imlpement all my scenarios apart the one below.

  • Every X weeks on Mon,Tue,Wed...

I managed to do this

0 31 15 ? * MON#2 *

which triggers every second Monday.

Would it work with 0 31 15 ? * MON#2,TUE#2,WED#2 * ??

I tried testing it on http://www.cronmaker.com however It only showed me Mondays as coming up dates. My only requirement is to keep it simple - ie. no more than one trigger.

3条回答
姐就是有狂的资本
2楼-- · 2019-06-17 10:15

I agree with Brabster.
I don't think it is possible with a Cron Expression.

Quartz.net 2.0 has a new type of trigger called CalendarIntervalTrigger which can be used to manage different interval units. You can read more here.

UPDATE:

Here's the link to the quartz.net 2.0 repository.

查看更多
Bombasti
3楼-- · 2019-06-17 10:26

One possible solution would to have a trigger that fired every week attached to a job that figures out if X number of weeks has passed and starts the main job.

This might go against your 'keep it simple' requirement but it would be functional. I've had to implement something similar to ensure specific Job instances are triggered rather than a brand new instance.

You might want to look at this question as its asking pretty much the same thing.

查看更多
Luminary・发光体
4楼-- · 2019-06-17 10:39

I've used the Java Quartz implementation, assuming they are similar then I don't think it's possible to express what you need as a single CronTrigger.

In Java we have the DateIntervalTrigger, but I don't think this could do what you need in a single trigger either. Unfortunately, as triggers can't be composed in the API itself,I guess there will be limits as to the complexity of triggers that can be expressed as a single trigger.

查看更多
登录 后发表回答