-
-
Notifications
You must be signed in to change notification settings - Fork 244
Create a non-linear retry policy. #1065
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
Changes from all commits
5e0d214
761ad9d
40e3493
9f522f3
f857d53
94927bc
b7f73b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| import os | ||
| from pathlib import Path | ||
| import platform | ||
| from typing import Tuple, cast, Any | ||
| from typing import Tuple, cast, Any, Optional | ||
| import warnings | ||
|
|
||
| from io import StringIO | ||
|
|
@@ -95,11 +95,10 @@ def set_file_log_level(file_output_level: int): | |
| else os.path.join("~", ".openml") | ||
| ), | ||
| "avoid_duplicate_runs": "True", | ||
| "connection_n_retries": "10", | ||
| "max_retries": "20", | ||
| "retry_policy": "human", | ||
| "connection_n_retries": "5", | ||
| } | ||
|
|
||
|
|
||
| # Default values are actually added here in the _setup() function which is | ||
| # called at the end of this module | ||
| server = str(_defaults["server"]) # so mypy knows it is a string | ||
|
|
@@ -122,9 +121,26 @@ def get_server_base_url() -> str: | |
| cache_directory = str(_defaults["cachedir"]) # so mypy knows it is a string | ||
| avoid_duplicate_runs = True if _defaults["avoid_duplicate_runs"] == "True" else False | ||
|
|
||
| # Number of retries if the connection breaks | ||
| retry_policy = _defaults["retry_policy"] | ||
| connection_n_retries = int(_defaults["connection_n_retries"]) | ||
| max_retries = int(_defaults["max_retries"]) | ||
|
|
||
|
|
||
| def set_retry_policy(value: str, n_retries: Optional[int] = None) -> None: | ||
|
Collaborator
Author
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. Due to the |
||
| global retry_policy | ||
| global connection_n_retries | ||
| default_retries_by_policy = dict(human=5, robot=50) | ||
|
|
||
| if value not in default_retries_by_policy: | ||
| raise ValueError( | ||
| f"Detected retry_policy '{value}' but must be one of {default_retries_by_policy}" | ||
| ) | ||
| if n_retries is not None and not isinstance(n_retries, int): | ||
| raise TypeError(f"`n_retries` must be of type `int` or `None` but is `{type(n_retries)}`.") | ||
| if isinstance(n_retries, int) and n_retries < 1: | ||
| raise ValueError(f"`n_retries` is '{n_retries}' but must be positive.") | ||
|
|
||
| retry_policy = value | ||
| connection_n_retries = default_retries_by_policy[value] if n_retries is None else n_retries | ||
|
|
||
|
|
||
| class ConfigurationForExamples: | ||
|
|
@@ -205,8 +221,6 @@ def _setup(config=None): | |
| global server | ||
| global cache_directory | ||
| global avoid_duplicate_runs | ||
| global connection_n_retries | ||
| global max_retries | ||
|
|
||
| config_file = determine_config_file_path() | ||
| config_dir = config_file.parent | ||
|
|
@@ -238,8 +252,12 @@ def _get(config, key): | |
| apikey = _get(config, "apikey") | ||
| server = _get(config, "server") | ||
| short_cache_dir = _get(config, "cachedir") | ||
| connection_n_retries = int(_get(config, "connection_n_retries")) | ||
| max_retries = int(_get(config, "max_retries")) | ||
|
|
||
| n_retries = _get(config, "connection_n_retries") | ||
| if n_retries is not None: | ||
| n_retries = int(n_retries) | ||
|
|
||
| set_retry_policy(_get(config, "retry_policy"), n_retries) | ||
|
|
||
| cache_directory = os.path.expanduser(short_cache_dir) | ||
| # create the cache subdirectory | ||
|
|
@@ -261,12 +279,6 @@ def _get(config, key): | |
| "not working properly." % config_dir | ||
| ) | ||
|
|
||
| if connection_n_retries > max_retries: | ||
| raise ValueError( | ||
| "A higher number of retries than {} is not allowed to keep the " | ||
| "server load reasonable".format(max_retries) | ||
| ) | ||
|
|
||
|
|
||
| def set_field_in_config_file(field: str, value: Any): | ||
| """ Overwrites the `field` in the configuration file with the new `value`. """ | ||
|
|
@@ -317,7 +329,7 @@ def get_config_as_dict(): | |
| config["cachedir"] = cache_directory | ||
| config["avoid_duplicate_runs"] = avoid_duplicate_runs | ||
| config["connection_n_retries"] = connection_n_retries | ||
| config["max_retries"] = max_retries | ||
| config["retry_policy"] = retry_policy | ||
| return config | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.