[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Revisiting every day x of nth month  XML
Forum Index -> Quartz
Author Message
Anonymous



Hi all,

I'm trying to figure out the best way to create a set of trigger(s) that can solve a schedule similar to the following:

Fire at 2PM on the 15th of every 5th month

This type of schedule was mentioned a year or two ago, and I did not see any proposed solutions for it. I know it's an obscure schedule, but it's a schedule type that Microsoft Outlook provides. I'm pretty sure, based on my own investigation, and a previous post to this message list, that it can not be solved with just a CronTrigger or SimpleTrigger alone.

So how do I solve this? Do I create a simpler trigger that fires more often, and then bury some additional logic in the job? Do I write my own trigger implementation(yikes!)? Any ideas, or thoughts? I'd appreciate any help!

For reference, here is what James House said in that previous posting:

"

No, you won't be able to do it with a single trigger - at least not with a trigger of a type that ships with Quartz out of the box.

SimpleTrigger could handle it if it was always N days between firings, but because some months have more days than others, it won't work for keeping the trigger on the same day of the month.

CronTrigger can handle the 15th of every month, or every other month, or every third, fourth, or sixth month. It is because you have an interval that does not even divide 12 that you have the problem. The "1/5" notation means "turn the trigger on for every fifth month in the set of months, starting with month 1" - which yields month 1, 6 and 11. Of course as the year ends, you then only get two month gap between firings in month 11 and month 1. This works out fine as I said if you have an interval that can evenly factor 12.

You're the first one I can recall hearing of in the 7 years of Quartz to need such an odd schedule -- few business cycles are occur every 5th month. Though I do recall someone once had the same problem for the minute position of the expression, because they wanted the trigger to fire every 17th minute, which does not evenly divide 60. Luckily for them, "every 17 minutes" can be easily accomplished with SimpleTrigger.

james
"

Thanks again!

Chris
jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline

Yes, unfortunately you are correct, that there is not a trigger implementation that will handle the expression.

CronTrigger cannot accomplish it because 12 (number of months) is not divisible by 5.

SimpleTrigger cannot accomplish it because the interval between the 15ths of each month is not equal.

Other triggers (e.g. NthIncludedDayTrigger) have similar problems.

Your options are likely:

1- Write your own trigger implementation - and consider contributing back the the project a "NthOfTheMonth" trigger.
2- Use CronTrigger with a monthly schedule, then add code in the job to check if it has yet been 5 months since it ran, and if not, bail-out
3- Use CronTrigger or SimpleTrigger, and have the job reschedule itself for five months later as it completes. (Or use a TriggerListener or JobListener to do the rescheduling, so keep that logic out of the job).


good luck,
james

jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline


Actually, a small extension/patch to cron trigger could enable the feature as well.
Anonymous



Hi James,

Thanks for the quick response! I'll give your suggestions some more thought.

Thanks again!

Chris Walzl
 
Forum Index -> Quartz
Go to:   
Powered by JForum 2.1.7 © JForum Team