Hybris 运行 月末前 'x' 天的 cron 作业
Hybris run a cron job 'x' days before month end
我想在 Hybris 中创建一个 cron 作业,它可以 运行 在一个月前的 5 天 end.I 使用
做一些事情
0 23 22-31 * * [ $(date -d +1day +%d) -eq 1 ]
在 hybris cron job impex 配置中与此等效的是什么。
hybris 使用 Quartz 2,如 documentation 所示。
来自石英 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.
所以你可以使用 0 0 0 L-5 * ?
。
注意:在较旧的 hybris 版本 (v4) 上,我不确定 Quartz 2 是否可用。对于 Quartz 1,您不能使用 L-x
模式。
如果您想要恰好在月底前 5 天,您应该创建 3 个触发器。
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...
还有另一种解决方案,但要复杂得多。
您可以设置第一次需要的触发器运行。然后在您的作业中,您可以访问 LocaleDate 对象以确定下一次作业应触发的时间。最后使用 Java 代码或 impex creation+import 更新 cronjob 的触发器。
我找到了更好的解决方案,使用石英
0 0 0 L-5 * ? *
我想在 Hybris 中创建一个 cron 作业,它可以 运行 在一个月前的 5 天 end.I 使用
做一些事情0 23 22-31 * * [ $(date -d +1day +%d) -eq 1 ]
在 hybris cron job impex 配置中与此等效的是什么。
hybris 使用 Quartz 2,如 documentation 所示。
来自石英 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.
所以你可以使用 0 0 0 L-5 * ?
。
注意:在较旧的 hybris 版本 (v4) 上,我不确定 Quartz 2 是否可用。对于 Quartz 1,您不能使用 L-x
模式。
如果您想要恰好在月底前 5 天,您应该创建 3 个触发器。
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...
还有另一种解决方案,但要复杂得多。
您可以设置第一次需要的触发器运行。然后在您的作业中,您可以访问 LocaleDate 对象以确定下一次作业应触发的时间。最后使用 Java 代码或 impex creation+import 更新 cronjob 的触发器。
我找到了更好的解决方案,使用石英
0 0 0 L-5 * ? *