-
Notifications
You must be signed in to change notification settings - Fork 65
echonet: refactor l1 client, add init, share retry func #10416
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
echonet: refactor l1 client, add init, share retry func #10416
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
7da3abf to
55d7bbb
Compare
matanl-starkware
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.
@matanl-starkware reviewed 1 of 2 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ayeletstarkware)
echonet/l1_client.py line 41 at r2 (raw file):
self, api_key: str, logger: logging.Logger,
Usually, it's the responsibility of the class to create its own logger.
If you want, it's possible to supply a logger "name" externally, but that's also not useful most of the times.
Code quote (i):
logger: logging.Logger,Code snippet (ii):
self.logger = logging.Logger('L1Client')echonet/l1_client.py line 55 at r2 (raw file):
self, request_func: Callable[[], Dict], method_name_for_logs: str,
Consider getting this from the call stack
Suggestion:
import inspect
def caller():
callee()
def callee():
caller_frame = inspect.currentframe().f_back
print(caller_frame.f_code.co_name)
caller() # prints: callerechonet/l1_client.py line 105 at r2 (raw file):
response = requests.post(self.rpc_url, json=payload, timeout=self.timeout) response.raise_for_status() return response.json()
Move the error handling and response parsing to the common retries function.
Suggestion:
request_func = lambda: requests.post(self.rpc_url, json=payload, timeout=self.timeout)echonet/l1_client.py line 106 at r2 (raw file):
response.raise_for_status() return response.json()
Another alternative:
Leave the "timeout" handling to the retries function.
Code snippet:
request_func = functools.partial(requests.post, self.rpc_url, json=payload)
...
response = request_func(timeout=self.timeout)55d7bbb to
739b502
Compare
ayeletstarkware
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.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @matanl-starkware)
echonet/l1_client.py line 41 at r2 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Usually, it's the responsibility of the class to create its own logger.
If you want, it's possible to supply a logger "name" externally, but that's also not useful most of the times.
Done.
echonet/l1_client.py line 55 at r2 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Consider getting this from the call stack
Cool!
echonet/l1_client.py line 105 at r2 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Move the error handling and response parsing to the common retries function.
used functools
echonet/l1_client.py line 106 at r2 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Another alternative:
Leave the "timeout" handling to the retries function.
Done.
matanl-starkware
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.
@matanl-starkware reviewed 2 of 2 files at r3, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware)

No description provided.