Shivanshu Bagga
Shivanshu Bagga

Reputation: 55

Hybris run a cron job 'x' days before month end

I want to create a cron job in Hybris that can run 5 days before the month end.I'm do some using

0 23 22-31 * * [ $(date -d +1day +%d) -eq 1 ]

What is equivalent to this in hybris cron job impex configuration.

Upvotes: 3

Views: 1361

Answers (2)

alain.janinm
alain.janinm

Reputation: 20065

hybris uses Quartz 2 as shown in the documentation.

From Quartz 2 documentation :

The ‘L’ character is allowed for the day-of-month and day-of-week fields. This character is short-hand for “last”, but it has different meaning in each of the two fields. For example, the value “L” in the day-of-month field means “the last day of the month” - day 31 for January, day 28 for February on non-leap years.[...] You can also specify an offset from the last day of the month, such as “L-3” which would mean the third-to-last day of the calendar month. When using the ‘L’ option, it is important not to specify lists, or ranges of values, as you’ll get confusing/unexpected results.

So you can use that 0 0 0 L-5 * ?.


Note: on older hybris version (v4) I'm not sure Quartz 2 was available. With Quartz 1 you can't use the L-x pattern. If you want exactly 5 days before end of month you should create 3 triggers.

0 0 20 26 1,3,5,7,8,10,12 ? * -> the 26th at 20h for all 31 days month

0 0 20 25 4,6,9,11 ? *  -> the 25th at 20h for all 30 days month

0 0 20 23 2 ? * -> the 23rd at 20h for february, this is actually a corner case because you may have different day for february...

There is also an other solution, but much more complex.

You can set a trigger for the first time it needs to run. Then in your job you can access a LocaleDate object to determine the next time the job should trigger. Finally update the trigger of the cronjob with Java code or impex creation+import.

Upvotes: 2

Shivanshu Bagga
Shivanshu Bagga

Reputation: 55

I found better solution , using quartz

0 0 0 L-5 * ? *

ref

Upvotes: 2

Related Questions