-
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
compare vversion in the schduler #63
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,25 +32,29 @@ def get_mongo_db() -> MongoDatabase: | |
return _client[os.getenv("MONGO_DBNAME")] | ||
|
||
|
||
def within_range(wf1: Workflow, wf2: Workflow, force=False) -> bool: | ||
def within_range(wf1: Workflow, wf2: Workflow, version_range: str, force: bool = False) -> bool: | ||
""" | ||
Determine if two workflows are within a major and minor | ||
version of each other. | ||
Determine if two workflows are within a specified version component of each other. | ||
The version_range parameter can be 'major', 'minor', or 'patch'. | ||
""" | ||
|
||
def get_version(wf): | ||
v_string = wf1.version.lstrip("b").lstrip("v") | ||
v_string = wf.version.lstrip("b").lstrip("v") | ||
return Version.parse(v_string) | ||
|
||
# Apples and oranges | ||
# Check for different workflow names | ||
if wf1.name != wf2.name: | ||
return False | ||
|
||
v1 = get_version(wf1) | ||
v2 = get_version(wf2) | ||
|
||
if force: | ||
return v1==v2 | ||
if v1.major == v2.major and v1.minor == v2.minor: | ||
return v1 == v2 | ||
|
||
if getattr(v1, version_range) == getattr(v2, version_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. This would just fetch the major minor or patch of the version right? It seems like this isn't quite right. Do you have a test that is something like 1.1, 2.1, "minor"? I'm thinking this would match when it shouldn't. |
||
return True | ||
|
||
return False | ||
|
||
|
||
|
@@ -233,7 +237,7 @@ def get_existing_jobs(self, wf: Workflow): | |
existing_jobs.add(act) | ||
return existing_jobs | ||
|
||
def find_new_jobs(self, act: Activity) -> list[Job]: | ||
def find_new_jobs(self, act: Activity, compare_version: str) -> list[Job]: | ||
""" | ||
For a given activity see if there are any new jobs | ||
that should be created. | ||
|
@@ -251,7 +255,7 @@ def find_new_jobs(self, act: Activity) -> list[Job]: | |
# Look at previously generated derived | ||
# activities to see if this is already done. | ||
for child_act in act.children: | ||
if within_range(child_act.workflow, wf, force=self.force): | ||
if within_range(child_act.workflow, wf, compare_version, force=self.force): | ||
break | ||
else: | ||
# These means no existing activities were | ||
|
@@ -262,7 +266,7 @@ def find_new_jobs(self, act: Activity) -> list[Job]: | |
|
||
return new_jobs | ||
|
||
def cycle(self, dryrun: bool = False, skiplist: set = set(), allowlist = None) -> list: | ||
def cycle(self, dryrun: bool = False, skiplist: set = set(), allowlist = None, compare_version: str = "major") -> list: | ||
""" | ||
This function does a single cycle of looking for new jobs | ||
""" | ||
|
@@ -275,7 +279,7 @@ def cycle(self, dryrun: bool = False, skiplist: set = set(), allowlist = None) - | |
continue | ||
if allowlist and act.was_informed_by not in allowlist: | ||
continue | ||
jobs = self.find_new_jobs(act) | ||
jobs = self.find_new_jobs(act, compare_version) | ||
for job in jobs: | ||
if dryrun: | ||
msg = f"new job: informed_by: {job.informed_by} trigger: {job.trigger_id} " | ||
|
@@ -312,8 +316,12 @@ def main(): # pragma: no cover | |
with open(os.environ.get("ALLOWLISTFILE")) as f: | ||
for line in f: | ||
allowlist.add(line.rstrip()) | ||
if os.environ.get("COMPAREVERSION"): | ||
compare_version = os.environ.get("COMPAREVERSION") | ||
else: | ||
compare_version = "major" | ||
while True: | ||
sched.cycle(dryrun=dryrun, skiplist=skiplist, allowlist=allowlist) | ||
sched.cycle(dryrun=dryrun, skiplist=skiplist, allowlist=allowlist, compare_version=compare_version) | ||
_sleep(_POLL_INTERVAL) | ||
|
||
|
||
|
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.
Maybe add a test and raise a ValueError if version_range isn't in the allowed options.