-
Notifications
You must be signed in to change notification settings - Fork 28
Permit single time cron expressions #123
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
Permit single time cron expressions #123
Conversation
jdforde
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming that you tested this locally, but changes LGTM
9884426 to
937b761
Compare
|
Manually tested cron expressions such as |
1879385 to
af19d25
Compare
|
Did you also test that you didn't break the behavior for recurring cron expressions? |
Yes, I have tested a few other basic cron expressions where the trigger is successfully created with the appropriate minimum window time, such as There are also tons of cron expressions tested in the |
tmccombs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, it wasn't obvious to me why this solves the problem. It took me a while to figure out this just allows setting the monitor time to Int.maxValue to bypass the interval check. Which is definitely not obvious.
I think it would be better to have getMaxInterval return an Option, and if it is None, then we accept any value, but treat is Int.maxValue (or just disable monitoring).
|
|
||
| object CronHelper extends Logging { | ||
| val IMPOSSIBLE_MAX_INTERVAL: Long = Long.MaxValue | ||
| val IMPOSSIBLE_MAX_INTERVAL_MINUS_ONE: Int = Int.MaxValue - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is confusing. What does it mean if the interval is set to this?
This isn't actually IMPOSSIBLE_MAX_INTERVAL - 1, since it is 1 less than the Int.MaxValue.
The name should instead indicate what this value acutally means. And maybe a comment to clarify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to remove the IMPOSSIBLE_MAX_INTERVAL_MINUS_ONE variable in favor of using an Option
| val outermost = subexpressions(outermostIndex) | ||
| if (outermost.maxInterval == IMPOSSIBLE_MAX_INTERVAL) IMPOSSIBLE_MAX_INTERVAL | ||
| // When cron represents a past-time (or time too far in the future), the Long.MaxValue needs to be passed in | ||
| if (outermost.maxInterval == IMPOSSIBLE_MAX_INTERVAL) IMPOSSIBLE_MAX_INTERVAL_MINUS_ONE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this MAX_INTERVAL isn't really impossible anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to set these to None indicating that validation on the monitoring-interval wont take place
|
|
||
| // Need to bound Long values to Int when validating, since the formatter expects Int type | ||
| private def longToIntBounded(l: Long): Int = { | ||
| if (l > Int.MaxValue) IMPOSSIBLE_MAX_INTERVAL_MINUS_ONE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not Int.MaxValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to set these to None indicating that validation on the monitoring-interval wont take place
| maxInterval("0/15 * * 1-12 * ?") mustEqual 19 * DAY + 15 * SECOND // every 15 seconds on days 1-12 of the month | ||
| maxInterval("* * * * 1-11 ?") mustEqual 31 * DAY + SECOND // every second of every month except for december | ||
| maxInterval("* * * * * ? 1998") mustEqual IMPOSSIBLE // every second of 1998 | ||
| maxInterval("* * * * * ? 1998") mustEqual IMPOSSIBLE_MINUS_ONE // every second of 1998 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we probably want times in the past to be rejected, but times in the future are ok...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior of piezo-admin will already reject cron expressions that only run in the past.
However, we should still test the validator for the monitoring-window for these crons even if they attempt to come through.
af19d25 to
51daf10
Compare
51daf10 to
621d797
Compare
Cron expressions such as
* * * * * ? 1998(every second of 1998) and0 0 20 ? 10 WED#2 2025(2025-10-08 Wed 20:00:00) should be permitted to run, however they require thattriggerMaxErrorTimebe set to a value greater thanLong.MaxValuewhich is not possible. To allow for these cron expressions to run, we should permit any monitoring value >= 0 to be set