Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CronTab.floor / .ceil should return times at minute granularity #10239

Merged
merged 3 commits into from
Feb 9, 2025

Conversation

jglick
Copy link
Member

@jglick jglick commented Feb 4, 2025

f97b5b3 seems to have been calling previously unused utility methods.

cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
(#1216) shows how the actual trigger is checked at precise one-minute intervals, and
if (!checkBits(bits[0], checkCal.get(MINUTE)))
return false;
if (!checkBits(bits[1], checkCal.get(HOUR_OF_DAY)))
return false;
if (!checkBits(bits[2], checkCal.get(DAY_OF_MONTH)))
return false;
if (!checkBits(bits[3], checkCal.get(MONTH) + 1))
return false;
if (!checkBits(dayOfWeek, checkCal.get(Calendar.DAY_OF_WEEK) - 1))
return false;
does not even consider seconds or microseconds, so the form validation rendered at 2:17:23 would claim that */5 * * * * would next run at 2:20:23, which is not really true: it would run at 2:20:00, or very shortly thereafter, and at any rate not specifically at 23 seconds past the minute.

Testing done

Unit tests, and then some interactive sanity checks of form validation including of @hourly etc.

Proposed changelog entries

  • Form validation for cron schedules included seconds based on the current time, when in fact the trigger fires at minute-granularity slots.

Proposed upgrade guidelines

N/A

Desired reviewers

@Vlatombe

Before the changes are marked as ready-for-merge:

Maintainer checklist

Preview Give feedback

private static void assertFloorCeil(CronTab tab, Calendar now, String expectedFloor, String expectedCeil) {
var fmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
var nowFormatted = fmt.format(now.getTime());
var nowClone = (Calendar) now.clone();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware that floor and ceil mutate their argument.

Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback.

/label ready-for-merge

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Feb 8, 2025
Copy link

@A1exKH A1exKH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jglick LGTM.

@krisstern krisstern merged commit 1e89d00 into jenkinsci:master Feb 9, 2025
16 checks passed
@MarkEWaite MarkEWaite added the bug For changelog: Minor bug. Will be listed after features label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants