-
Notifications
You must be signed in to change notification settings - Fork 21
Use longer server start timeout by default #40
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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 hidden or 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 |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ def __init__(self, token, timeout=None): # noqa | |
| self.token = token | ||
| self.timeout = timeout | ||
|
|
||
| def request(self, method, endpoint, body=None): | ||
| def request(self, method, endpoint, body=None, timeout=-1): | ||
| """ | ||
| Perform a request with a given body to a given endpoint in UpCloud's API. | ||
|
|
||
|
|
@@ -38,11 +38,13 @@ def request(self, method, endpoint, body=None): | |
| else: | ||
| json_body_or_None = None | ||
|
|
||
| call_timeout = timeout if timeout != -1 else self.timeout | ||
|
Contributor
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. When timeout is None, this could be stated as: call_timeout = timeout or self.timeout |
||
|
|
||
| APIcall = getattr(requests, method.lower()) | ||
| res = APIcall('https://api.upcloud.com' + url, | ||
| data=json_body_or_None, | ||
| headers=headers, | ||
| timeout=self.timeout) | ||
| timeout=call_timeout) | ||
|
|
||
| if res.text: | ||
| res_json = res.json() | ||
|
|
@@ -51,17 +53,17 @@ def request(self, method, endpoint, body=None): | |
|
|
||
| return self.__error_middleware(res, res_json) | ||
|
|
||
| def get_request(self, endpoint): | ||
| def get_request(self, endpoint, timeout=-1): | ||
| """ | ||
| Perform a GET request to a given endpoint in UpCloud's API. | ||
| """ | ||
| return self.request('GET', endpoint) | ||
| return self.request('GET', endpoint, timeout=timeout) | ||
|
|
||
| def post_request(self, endpoint, body=None): | ||
| def post_request(self, endpoint, body=None, timeout=-1): | ||
| """ | ||
| Perform a POST request to a given endpoint in UpCloud's API. | ||
| """ | ||
| return self.request('POST', endpoint, body) | ||
| return self.request('POST', endpoint, body, timeout) | ||
|
|
||
| def __error_middleware(self, res, res_json): | ||
| """ | ||
|
|
||
This file contains hidden or 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
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 would prefer timeout to be None
Uh oh!
There was an error while loading. Please reload this page.
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.
The point for the default not to be
Noneis that one can then call the method withtimeout=Noneto disable the timeout altogether. (See complete commit message of the first commit.) That's consistent with how one can disable timeouts for the whole manager.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.
ok, works for me :D, merging