-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat: accept cron schedule for analyzers #56
Merged
+139
−7
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class SplitCron: | ||
day_of_week: str | ||
month: str | ||
day_of_month: str | ||
hour: str | ||
minute: str | ||
|
||
|
||
def split_cron_expression(cron: str) -> SplitCron: | ||
"""Split the cron expression into its components.""" | ||
cron_slots = cron.split(" ") | ||
if len(cron_slots) != 5: | ||
raise ValueError("CronSchedule must have 5 fields.") | ||
return SplitCron( | ||
day_of_week=cron_slots[0], | ||
month=cron_slots[1], | ||
day_of_month=cron_slots[2], | ||
hour=cron_slots[3], | ||
minute=cron_slots[4], | ||
) | ||
|
||
|
||
def _is_not_less_granular_than_1_hour(split_cron: SplitCron) -> bool: | ||
"""Check if the cron expression is less granular than 1 hour.""" | ||
# Specific days checks | ||
if split_cron.minute != "*" and split_cron.minute != "0": | ||
return True | ||
if split_cron.hour != "*" and split_cron.hour != "0": | ||
return True | ||
if split_cron.day_of_month != "*" and split_cron.day_of_month != "1": | ||
return True | ||
if split_cron.month != "*" and split_cron.month != "1": | ||
return True | ||
if split_cron.day_of_week != "*" and split_cron.day_of_week != "1": | ||
return True | ||
|
||
# Check range | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all that happens from here on is that it iterates and then returns False... logic seems wrong. Also seems disconnected from "is granularity less than hour", seems like it is meant to be checking any range fields |
||
for field in (split_cron.day_of_week, split_cron.month, split_cron.day_of_month, split_cron.hour): | ||
for item in field.split(","): | ||
if "-" in item: | ||
start, end = map(int, item.split("-")) | ||
if end - start > 0: | ||
return False | ||
return False | ||
|
||
|
||
def validate_cron_expression(cron: str) -> bool: | ||
split_cron = split_cron_expression(cron) | ||
return _is_not_less_granular_than_1_hour(split_cron=split_cron) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 dont get why it needs to check that its not 0 (and ditto for the other fields). Seems like this check should fail if the minute is '*' or anything with a - or , in it. Anything else would be 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.
true. it really doesn't make sense to check for the "top of the {time}"