Skip to content

Commit

Permalink
Issue #365 Made job manager's retry settings more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanKJSchreurs committed Jan 31, 2023
1 parent ffd8a84 commit efef2e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 6 additions & 8 deletions openeo/extra/job_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
_Backend = collections.namedtuple("_Backend", ["get_connection", "parallel_jobs"])


MAX_RETRIES = 5

class MultiBackendJobManager:
"""
Tracker for multiple jobs on multiple backends.
Expand Down Expand Up @@ -135,16 +137,12 @@ def _make_resilient(self, connection):
503 Service Unavailable
504 Gateway Timeout
"""

status_forcelist = [502, 503, 504]

# TODO: Check the number of retries for each type.
# I think `total` actually overrides all the other ones that are currently set to a higher number.
retries = Retry(
total=5,
read=50,
other=50,
status=50,
total=MAX_RETRIES,
read=MAX_RETRIES,
other=MAX_RETRIES,
status=MAX_RETRIES,
backoff_factor=0.1,
status_forcelist=status_forcelist,
allowed_methods=["HEAD", "GET", "OPTIONS", "POST"],
Expand Down
8 changes: 3 additions & 5 deletions tests/extra/test_job_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


import openeo
from openeo.extra.job_management import MultiBackendJobManager
from openeo.extra.job_management import MultiBackendJobManager, MAX_RETRIES
from openeo import BatchJob

class TestMultiBackendJobManager:
Expand Down Expand Up @@ -211,7 +211,6 @@ def test_is_resilient_to_backend_failures(self, tmp_path, http_error_status):

backend = "http://foo.test"
job_id = "job-2018"
max_retries = 5

httpretty.register_uri(
"GET", backend, body=json.dumps({"api_version": "1.1.0"})
Expand All @@ -222,7 +221,7 @@ def test_is_resilient_to_backend_failures(self, tmp_path, http_error_status):
corehttpretty.Response(
f"Simulate error HTTP {http_error_status}", status=http_error_status
)
] * max_retries
] * MAX_RETRIES
response_list += [
corehttpretty.Response(
body=json.dumps(
Expand Down Expand Up @@ -284,7 +283,6 @@ def test_resilient_backend_reports_error_when_max_retries_exceeded(

backend = "http://foo.test"
job_id = "job-2018"
max_retries = 5

httpretty.register_uri(
"GET", backend, body=json.dumps({"api_version": "1.1.0"})
Expand All @@ -309,7 +307,7 @@ def test_resilient_backend_reports_error_when_max_retries_exceeded(
corehttpretty.Response(
f"Simulate error HTTP {http_error_status}", status=http_error_status
)
] * (max_retries + 1)
] * (MAX_RETRIES + 1)

httpretty.register_uri(
"GET", f"{backend}/jobs/{job_id}", responses=response_list
Expand Down

0 comments on commit efef2e2

Please sign in to comment.