Skip to content

Commit 9875b30

Browse files
committed
Fix based on reviews
1 parent bec4614 commit 9875b30

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

launchable/commands/subset.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
from typing import Any, Callable, Dict, List, Optional, Sequence, TextIO, Tuple, Union
99

1010
import click
11-
from requests import Session
12-
from requests.adapters import HTTPAdapter
1311
from tabulate import tabulate
1412

1513
from launchable.utils.authentication import get_org_workspace
16-
from launchable.utils.http_client import MAX_RETRIES, default_retry_strategy
1714
from launchable.utils.session import parse_session
1815
from launchable.utils.tracking import Tracking, TrackingClient
1916

@@ -508,19 +505,8 @@ def run(self):
508505
else:
509506
try:
510507
test_runner = context.invoked_subcommand
511-
512-
strategy = default_retry_strategy()
513-
# Requesting a subset may require retrying the requests because it takes time to load
514-
# models on the Launchable side.
515-
# Therefore, we make an exception to allow retries.
516-
strategy.read = MAX_RETRIES
517-
adapter = HTTPAdapter(max_retries=strategy)
518-
s = Session()
519-
s.mount("http://", adapter)
520-
s.mount("https://", adapter)
521508
client = LaunchableClient(
522509
test_runner=test_runner,
523-
session=s,
524510
app=app,
525511
tracking_client=tracking_client)
526512

launchable/utils/env_keys.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
ORGANIZATION_KEY = "LAUNCHABLE_ORGANIZATION"
44
WORKSPACE_KEY = "LAUNCHABLE_WORKSPACE"
55
BASE_URL_KEY = "LAUNCHABLE_BASE_URL"
6+
SKIP_TIMEOUT_RETRY = "LAUNCHABLE_SKIP_TIMEOUT_RETRY"

launchable/utils/http_client.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from click import Context
99
from requests import Session
1010
from requests.adapters import HTTPAdapter
11-
from urllib3.util.retry import Retry
11+
from requests.packages.urllib3.util.retry import Retry # type: ignore
1212

1313
from launchable.version import __version__
1414

1515
from ..app import Application
1616
from .authentication import authentication_headers
17-
from .env_keys import BASE_URL_KEY
17+
from .env_keys import BASE_URL_KEY, SKIP_TIMEOUT_RETRY
1818
from .gzipgen import compress as gzipgen_compress
1919
from .logger import AUDIT_LOG_FORMAT, Logger
2020

@@ -31,18 +31,6 @@ def get_base_url():
3131
return os.getenv(BASE_URL_KEY) or DEFAULT_BASE_URL
3232

3333

34-
def default_retry_strategy():
35-
return Retry(
36-
total=MAX_RETRIES,
37-
# When Launchable server is unstable, ReadTimeout can occur.
38-
# To prevent the execution from slowing down, we disable retrying the request in this case.
39-
read=0,
40-
allowed_methods=["GET", "PUT", "PATCH", "DELETE"],
41-
status_forcelist=[429, 500, 502, 503, 504],
42-
backoff_factor=2
43-
)
44-
45-
4634
class DryRunResponse:
4735
def __init__(self, status_code, payload):
4836
self.status_code = status_code
@@ -63,7 +51,17 @@ def __init__(self, base_url: str = "", session: Optional[Session] = None,
6351
self.skip_cert_verification = bool(app and app.skip_cert_verification)
6452

6553
if session is None:
66-
strategy = default_retry_strategy()
54+
read = MAX_RETRIES
55+
if os.getenv(SKIP_TIMEOUT_RETRY):
56+
read = 0
57+
strategy = Retry(
58+
total=MAX_RETRIES,
59+
read=read,
60+
allowed_methods=["GET", "PUT", "PATCH", "DELETE"],
61+
status_forcelist=[429, 500, 502, 503, 504],
62+
backoff_factor=2
63+
)
64+
6765
adapter = HTTPAdapter(max_retries=strategy)
6866
s = Session()
6967
s.mount("http://", adapter)

0 commit comments

Comments
 (0)