Skip to content

feat: fall back to random distribution - #148

Merged
uniqueg merged 4 commits into
devfrom
fix/fallback-to-random-distribution
Mar 16, 2023
Merged

uniqueg merged 4 commits into
devfrom
fix/fallback-to-random-distribution

Conversation

@Ayush5120

@Ayush5120 Ayush5120 commented Mar 15, 2023 •

Copy link
Copy Markdown
Contributor

Fall back to random task distribution if distance-based task distribution fails.

Partially fixes #134

@uniqueg uniqueg changed the title fix: fallback to random distribution on distance-based logic failure feat: fallback to random distribution Mar 15, 2023
Comment on lines +47 to +51
try:
ips = ip_combination(input_uri=input_uri, tes_uri=tes_uri)
except (InputUriError, TesUriError):
return random.task_distribution()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the different middlewares should not be coupled. So I think this should be implemented outside of distance.py, i.e., raise the error here, then catch it in the calling context and use the alternative middleware instead.

@Ayush5120
Ayush5120 requested a review from uniqueg March 16, 2023 12:24

@uniqueg uniqueg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're getting there :)

Comment thread pro_tes/middleware/middleware.py Outdated
@@ -62,7 +67,15 @@ def modify_request(self, request):
)

if self.input_uris:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens in distance.task_distribution() if self.input_uris is empty? Will it raise one of the errors you are catching?

If so (and it probably should!), there's no point in doing the if-else anymore - you can just do the try and except.

@Ayush5120 Ayush5120 Mar 16, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No the errors mentioned, do not respond to empty input URI, there was just an outside check, I can remove the outside check and maybe raise a ValueError in distance.py with a message ( "No input URI available) and then catch the error hence, removing the if-else block.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yup. It doesn't make sense to use the distance-based logic if there are no inputs, so I think it would be good to raise a ValueError and then catch that outside and remove the if-else.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, fixed in the last commit.

Comment on lines +48 to +51
except InputUriError as exc:
raise InputUriError from exc
except TesUriError as exc:
raise TesUriError from exc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's no point in doing that. Just let the error raise itself, implicitly! That is, remove the entire try-except here. Then you also do not need to document the exceptions in Raises in the docstring (which otherwise you would have needed to add, try to remember that).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Understood, will fix it in the next commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines +62 to +65
except IPDistanceCalculationError as exc:
raise IPDistanceCalculationError from exc
except KeyError as exc:
raise KeyError from exc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above, just remove the try-except.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@uniqueg uniqueg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're getting there. Just one very small change left :)

Comment on lines +48 to +50
if not input_uri:
raise ValueError("No input URIs available.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For performance reasons, this should come before anything else in this method. Especially because you are already using input_uri in the previous statement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@uniqueg uniqueg changed the title feat: fallback to random distribution feat: fall back to random distribution Mar 16, 2023
@uniqueg
uniqueg merged commit 9422756 into dev Mar 16, 2023
@uniqueg
uniqueg deleted the fix/fallback-to-random-distribution branch March 16, 2023 20:30
keshxvdayal pushed a commit that referenced this pull request Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Several issues with TES/input URI processing in distance-based task distribution logic

2 participants