Skip to content

Commit

Permalink
Merge branch 'fix/rate_limiting_for_all_deployments' into 'master'
Browse files Browse the repository at this point in the history
Feature - rate limiting for all deployments

See merge request team-6/openeo-sentinelhub-python-driver!321
  • Loading branch information
zansinergise committed Oct 13, 2023
2 parents 08a4fe9 + 36eaa96 commit b7fdf90
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
6 changes: 5 additions & 1 deletion rest/processing/processing_api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def make_request(self):
return requests.post(self.url, data=json.dumps(self.data), headers=self.get_headers())

def has_rate_limiting_with_backoff(self):
if self.url.startswith(SentinelhubDeployments.USWEST):
if (
self.url.startswith(SentinelhubDeployments.MAIN)
or self.url.startswith(SentinelhubDeployments.USWEST)
or self.url.startswith(SentinelhubDeployments.CREODIAS)
):
return True
return False
71 changes: 68 additions & 3 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,40 @@ def test_get_roles(filename, expected_roles):
"endpoint,access_token,api_responses,min_exec_time,should_raise_error,expected_error",
[
("https://services.sentinel-hub.com", None, [{"status": 200}], 0, False, None),
("https://services.sentinel-hub.com", None, [{"status": 429}], 0, True, "Too Many Requests"),
("https://services.sentinel-hub.com", "some-token", [{"status": 200}], 0, False, None),
("https://services.sentinel-hub.com", "some-token", [{"status": 429}], 0, True, "Too Many Requests"),
(
"https://services.sentinel-hub.com",
None,
[
{"status": 429, "headers": {"retry-after": "2"}},
{"status": 429, "headers": {"retry-after": "7"}},
{"status": 200},
],
9,
False,
None,
),
(
"https://services.sentinel-hub.com",
None,
[
{"status": 429, "headers": {"retry-after": "2"}},
{"status": 429, "headers": {"retry-after": "2"}},
{"status": 429, "headers": {"retry-after": "2"}},
{"status": 429, "headers": {"retry-after": "2"}},
],
0,
True,
"Out of retries.",
),
(
"https://services.sentinel-hub.com",
None,
[{"status": 429, "headers": {"retry-after": "2"}}, {"status": 500}],
0,
True,
"Internal Server Error",
),
("https://services-uswest2.sentinel-hub.com", None, [{"status": 200}], 0, False, None),
(
"https://services-uswest2.sentinel-hub.com",
None,
Expand Down Expand Up @@ -1022,6 +1053,40 @@ def test_get_roles(filename, expected_roles):
True,
"Internal Server Error",
),
("https://creodias.sentinel-hub.com", None, [{"status": 200}], 0, False, None),
(
"https://creodias.sentinel-hub.com",
None,
[
{"status": 429, "headers": {"retry-after": "2"}},
{"status": 429, "headers": {"retry-after": "7"}},
{"status": 200},
],
9,
False,
None,
),
(
"https://creodias.sentinel-hub.com",
None,
[
{"status": 429, "headers": {"retry-after": "2"}},
{"status": 429, "headers": {"retry-after": "2"}},
{"status": 429, "headers": {"retry-after": "2"}},
{"status": 429, "headers": {"retry-after": "2"}},
],
0,
True,
"Out of retries.",
),
(
"https://creodias.sentinel-hub.com",
None,
[{"status": 429, "headers": {"retry-after": "2"}}, {"status": 500}],
0,
True,
"Internal Server Error",
),
],
)
def test_processing_api_request(
Expand Down

0 comments on commit b7fdf90

Please sign in to comment.