Repository navigation
feat: fall back to random distribution - #148
Conversation
| try: | ||
| ips = ip_combination(input_uri=input_uri, tes_uri=tes_uri) | ||
| except (InputUriError, TesUriError): | ||
| return random.task_distribution() | ||
|
|
There was a problem hiding this comment.
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.
| @@ -62,7 +67,15 @@ def modify_request(self, request): | |||
| ) | |||
|
|
|||
| if self.input_uris: | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Okay, fixed in the last commit.
| except InputUriError as exc: | ||
| raise InputUriError from exc | ||
| except TesUriError as exc: | ||
| raise TesUriError from exc |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Understood, will fix it in the next commit.
| except IPDistanceCalculationError as exc: | ||
| raise IPDistanceCalculationError from exc | ||
| except KeyError as exc: | ||
| raise KeyError from exc |
There was a problem hiding this comment.
Same as above, just remove the try-except.
uniqueg
left a comment
There was a problem hiding this comment.
We're getting there. Just one very small change left :)
| if not input_uri: | ||
| raise ValueError("No input URIs available.") | ||
|
|
There was a problem hiding this comment.
For performance reasons, this should come before anything else in this method. Especially because you are already using input_uri in the previous statement.
Fall back to random task distribution if distance-based task distribution fails.
Partially fixes #134