Skip to content

Commit 4426881

Browse files
author
AidanAbd
committed
fix: tinyurl needs better backoff scheme
1 parent 7474c9a commit 4426881

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/latch/functions/secrets.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from urllib.parse import urljoin
22

3-
from latch_sdk_config.latch import NUCLEUS_URL
4-
53
from latch.utils import current_workspace
64
from latch_cli.tinyrequests import post
75
from latch_cli.utils import get_auth_header
6+
from latch_sdk_config.latch import NUCLEUS_URL
87

98

109
def get_secret(secret_name: str):
@@ -24,10 +23,7 @@ def get_secret(secret_name: str):
2423

2524
resp = post(
2625
url=urljoin(NUCLEUS_URL, "/secrets/get-new"),
27-
json={
28-
"name": secret_name,
29-
"ws_id": current_workspace(),
30-
},
26+
json={"name": secret_name, "ws_id": current_workspace()},
3127
headers={"Authorization": get_auth_header()},
3228
)
3329

src/latch_cli/tinyrequests.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def _req(
111111
return TinyResponse(resp, url, stream=stream)
112112

113113

114+
_retryable_status_codes = {429, 500, 502, 503, 504}
115+
116+
114117
def request(
115118
method: str,
116119
url: str,
@@ -121,8 +124,8 @@ def request(
121124
stream: bool = False,
122125
num_retries: int = 3,
123126
) -> TinyResponse:
124-
"""Send HTTP request. Retry on 500s or ConnectionErrors.
125-
Implements exponential backoff between retries.
127+
"""Send HTTP request. Retry on transient errors (429, 5xx, ConnectionError)
128+
with exponential backoff.
126129
"""
127130
err = None
128131
res = None
@@ -135,15 +138,13 @@ def request(
135138
res = _req(
136139
method, url, headers=headers, data=data, json=json, stream=stream
137140
)
138-
if res.status_code < 500:
141+
if res.status_code not in _retryable_status_codes:
139142
return res
140143
except ConnectionError as e:
141144
err = e
142145

143146
if attempt < num_retries:
144-
# todo(rahul): tune the sleep interval based on the startup time of the server
145-
# todo(rahul): change sleep interval based on which service we are calling
146-
time.sleep(2**attempt * 5)
147+
time.sleep(2**attempt)
147148

148149
if res is None:
149150
raise err

0 commit comments

Comments
 (0)