Skip to content
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

Rescale default retry times to correct units #507

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sentinelhub/download/rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ def register_next(self) -> float:
return wait_time

def update(self, headers: dict, *, default: float) -> None:
"""Update the next possible download time if the service has responded with the rate limit"""
"""Update the next possible download time if the service has responded with the rate limit.

:param headers: The headers that (may) contain information about waiting times.
:param default: The default waiting time (in milliseconds) when retrying after getting a
TOO_MANY_REQUESTS response without appropriate retry headers.
"""
retry_after: float = int(headers.get(self.RETRY_HEADER, default)) # can be a string representation of a number
retry_after = retry_after / 1000

Expand Down
6 changes: 3 additions & 3 deletions sentinelhub/download/sentinelhub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def __init__(self, *, session: SentinelHubSession | None = None, default_retry_t
:param session: If a session object is provided here then this client instance will always use only the
provided session. Otherwise, it will either use a cached session or create a new session and cache
it.
:param default_retry_time: The default waiting time when retrying after getting a TOO_MANY_REQUESTS response
without appropriate retry headers.
:param default_retry_time: The default waiting time (in seconds) when retrying after getting a TOO_MANY_REQUESTS
response without appropriate retry headers.
:param kwargs: Optional parameters from DownloadClient
"""
super().__init__(**kwargs)
Expand All @@ -51,7 +51,7 @@ def __init__(self, *, session: SentinelHubSession | None = None, default_retry_t
f"{session} was given"
)
self.session = session
self.default_retry_time = default_retry_time
self.default_retry_time = default_retry_time * 1000 # rescale to milliseconds

self.rate_limit = SentinelHubRateLimit(num_processes=self.config.number_of_download_processes)
self.lock: Lock | None = None
Expand Down