提交 5727f287 编写于 作者: J Jesse Glick

Warn in the UI about short cycles in the day of month field for a crontab,...

Warn in the UI about short cycles in the day of month field for a crontab, which can have surprising behaviors near the end of a month.
上级 84318cc9
......@@ -430,6 +430,16 @@ public final class CronTab {
}
}
int daysOfMonth = 0;
for (int i = 1; i < 31; i++) {
if (checkBits(bits[2], i)) {
daysOfMonth++;
}
}
if (daysOfMonth > 5 && daysOfMonth < 28) { // a bit arbitrary
return Messages.CronTab_short_cycles_in_the_day_of_month_field_w();
}
String hashified = hashify(spec);
if (hashified != null) {
return Messages.CronTab_spread_load_evenly_by_using_rather_than_(hashified, spec);
......
......@@ -24,5 +24,6 @@ BaseParser.StartEndReversed=You mean {0}-{1}?
BaseParser.MustBePositive=step must be positive, but found {0}
BaseParser.OutOfRange={0} is an invalid value. Must be within {1} and {2}
CronTab.do_you_really_mean_every_minute_when_you=Do you really mean "every minute" when you say "{0}"? Perhaps you meant "{1}"
CronTab.short_cycles_in_the_day_of_month_field_w=Short cycles in the day-of-month field will behave oddly near the end of a month
CronTab.spread_load_evenly_by_using_rather_than_=Spread load evenly by using \u2018{0}\u2019 rather than \u2018{1}\u2019
CronTabList.InvalidInput=Invalid input: "{0}": {1}
......@@ -50,6 +50,12 @@
but it actually is a hash of the job name, not a random function, so that
the value remains stable for any given project.
</p>
<p>
Beware that for the day of month field, short cycles such as <code>*/3</code> or <code>H/3</code> will not work consistently near the end of most months, due to variable month lengths.
For example, <code>*/3</code> will run on the 1st, 4th, …31st days of a long month, then again the next day of the next month.
Hashes are always chosen in the 1-28 range, so <code>H/3</code> will produce a gap between runs of between 3 and 6 days at the end of a month.
(Longer cycles will also have inconsistent lengths but the effect may be relatively less noticeable.)
</p>
<p>
Empty lines and lines that start with <code>#</code> will be ignored as comments.
</p><p>
......
......@@ -193,6 +193,9 @@ public class CronTabTest {
assertEquals(Messages.CronTab_spread_load_evenly_by_using_rather_than_("H 3 * * *", "0 3 * * *"), new CronTab("0 3 * * *").checkSanity());
assertEquals(Messages.CronTab_spread_load_evenly_by_using_rather_than_("H 22 * * 6", "00 22 * * 6"), new CronTab("00 22 * * 6").checkSanity());
assertEquals(null, new CronTab("H/15 * 1 1 *").checkSanity());
assertEquals(null, new CronTab("0 3 H/15 * *").checkSanity());
assertEquals(Messages.CronTab_short_cycles_in_the_day_of_month_field_w(), new CronTab("0 3 H/3 * *").checkSanity());
assertEquals(Messages.CronTab_short_cycles_in_the_day_of_month_field_w(), new CronTab("0 3 */5 * *").checkSanity());
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册