-
Notifications
You must be signed in to change notification settings - Fork 27
Adds CONNECT_REQUEST_TIMEOUT env variable #349
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
22 commits
Select commit
Hold shift + click to select a range
6d436f3
Adds CONNECT_REQUEST_TIMEOUT env variable.
tdstein 524c150
Merge branch 'master' into 346-add-timeout-configuration
tdstein 0dcaa97
Merge branch 'master' into 346-add-timeout-configuration
tdstein f1054aa
Adds notes to CHANGELOG for CONNECT_REQUEST_TIMEOUT.
tdstein 19f5a62
Merge branch 'master' into 346-add-timeout-configuration
tdstein b5c056f
Merge branch 'master' into 346-add-timeout-configuration
tdstein 796c901
add absolute path file list and use it for voila
bcwu f2f01e2
return list instead of string when default found
bcwu 8345999
add deploy html unittest files
bcwu 00f818b
deprecate legacy deploy_html functions
bcwu 5330a32
update infer_entrypoint_candidates to return absolute paths
bcwu d203ef7
refactor deploy_html with Manifest and Bundle
bcwu b4e7fd9
add unit tests for deploy_html manifest
bcwu c7f53f9
add primary_html to Manifest
bcwu e3bf8b2
check whether provided path and entrypoint exist
bcwu d2c28ea
optional absolute paths for validate_extra_files
bcwu 0d53796
add use_abspath flag to create_file_list
bcwu 4a627f9
add unit tests for make_html_bundle
bcwu 5735481
Update changelog
bcwu bad3188
correct description
bcwu 5c47917
Merge remote-tracking branch 'origin/master' into 346-add-timeout-con…
tdstein ce7d898
Merge branch 'master' into 346-add-timeout-configuration
tdstein 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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import os | ||
| from typing import Union | ||
|
|
||
| from rsconnect.exception import RSConnectException | ||
|
|
||
| _CONNECT_REQUEST_TIMEOUT_KEY = "CONNECT_REQUEST_TIMEOUT" | ||
| _CONNECT_REQUEST_TIMEOUT_DEFAULT_VALUE = "300" | ||
|
|
||
|
|
||
| def get_timeout() -> int: | ||
| """Gets the timeout from the CONNECT_REQUEST_TIMEOUT env variable. | ||
|
|
||
| The timeout value is intended to be interpreted in seconds. A value of 60 is equal to sixty seconds, or one minute. | ||
|
|
||
| If CONNECT_REQUEST_TIMEOUT is unset, a default value of 300 is used. | ||
|
|
||
| If CONNECT_REQUEST_TIMEOUT is set to a value less than 0, an `RSConnectException` is raised. | ||
|
|
||
| A CONNECT_REQUEST_TIMEOUT set to 0 is logically equivalent to no timeout. | ||
|
|
||
| The primary intent for this method is for usage with the `http` module. Specifically, for setting the timeout | ||
| parameter with an `http.client.HTTPConnection` or `http.client.HTTPSConnection`. | ||
|
|
||
| :raises: `RSConnectException` if CONNECT_REQUEST_TIMEOUT is not a natural number. | ||
| :return: the timeout value | ||
| """ | ||
| timeout: Union[int, str] = os.environ.get(_CONNECT_REQUEST_TIMEOUT_KEY, _CONNECT_REQUEST_TIMEOUT_DEFAULT_VALUE) | ||
|
|
||
| try: | ||
| timeout = int(timeout) | ||
| except ValueError: | ||
| raise RSConnectException( | ||
| f"'CONNECT_REQUEST_TIMEOUT' is set to '{timeout}'. The value must be a natural number." | ||
| ) | ||
|
|
||
| if timeout < 0: | ||
| raise RSConnectException( | ||
| f"'CONNECT_REQUEST_TIMEOUT' is set to '{timeout}'. The value must be a natural number." | ||
| ) | ||
|
|
||
| return timeout | ||
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
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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import os | ||
|
|
||
| from unittest import TestCase | ||
| from unittest.mock import patch | ||
|
|
||
| from rsconnect.exception import RSConnectException | ||
| from rsconnect.timeouts import get_timeout | ||
|
|
||
|
|
||
| class GetTimeoutTestCase(TestCase): | ||
tdstein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_get_default_timeout(self): | ||
| timeout = get_timeout() | ||
| self.assertEqual(300, timeout) | ||
|
|
||
| def test_get_valid_timeout_from_environment(self): | ||
| with patch.dict(os.environ, {"CONNECT_REQUEST_TIMEOUT": "24"}): | ||
| timeout = get_timeout() | ||
| self.assertEqual(24, timeout) | ||
|
|
||
| def test_get_zero_timeout_from_environment(self): | ||
| with patch.dict(os.environ, {"CONNECT_REQUEST_TIMEOUT": "0"}): | ||
| timeout = get_timeout() | ||
| self.assertEqual(0, timeout) | ||
|
|
||
| def test_get_invalid_timeout_from_environment(self): | ||
| with patch.dict(os.environ, {"CONNECT_REQUEST_TIMEOUT": "foobar"}): | ||
| with self.assertRaises(RSConnectException): | ||
| get_timeout() | ||
|
|
||
| def test_get_negative_timeout_from_environment(self): | ||
| with patch.dict(os.environ, {"CONNECT_REQUEST_TIMEOUT": "-24"}): | ||
| with self.assertRaises(RSConnectException): | ||
| get_timeout() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.