Skip to content

Commit

Permalink
feat(api): increase retries (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Nov 16, 2024
1 parent 431efde commit ff985bb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Error codes are as followed:

### Retries

Certain errors are automatically retried 2 times by default, with a short exponential backoff.
Certain errors are automatically retried 5 times by default, with a short exponential backoff.
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
429 Rate Limit, and >=500 Internal errors are all retried by default.

Expand All @@ -232,15 +232,15 @@ client.with_options(max_retries=5).agents.create_or_update(

### Timeouts

By default requests time out after 1 minute. You can configure this with a `timeout` option,
By default requests time out after 2 minutes. You can configure this with a `timeout` option,
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:

```python
from julep import Julep

# Configure the default for all requests:
client = Julep(
# 20 seconds (default is 1 minute)
# 20 seconds (default is 2 minutes)
timeout=20.0,
)

Expand Down
10 changes: 5 additions & 5 deletions src/julep/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"

# default timeout is 1 minute
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60.0, connect=5.0)
DEFAULT_MAX_RETRIES = 2
# default timeout is 2 minutes
DEFAULT_TIMEOUT = httpx.Timeout(timeout=120.0, connect=5.0)
DEFAULT_MAX_RETRIES = 5
DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)

INITIAL_RETRY_DELAY = 0.5
MAX_RETRY_DELAY = 8.0
INITIAL_RETRY_DELAY = 1.0
MAX_RETRY_DELAY = 10.0
56 changes: 28 additions & 28 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_copy_default_options(self) -> None:
# options that have a default are overridden correctly
copied = self.client.copy(max_retries=7)
assert copied.max_retries == 7
assert self.client.max_retries == 2
assert self.client.max_retries == 5

copied2 = copied.copy(max_retries=6)
assert copied2.max_retries == 6
Expand Down Expand Up @@ -680,21 +680,21 @@ class Model(BaseModel):
"remaining_retries,retry_after,timeout",
[
[3, "20", 20],
[3, "0", 0.5],
[3, "-10", 0.5],
[3, "0", 1],
[3, "-10", 1],
[3, "60", 60],
[3, "61", 0.5],
[3, "61", 1],
[3, "Fri, 29 Sep 2023 16:26:57 GMT", 20],
[3, "Fri, 29 Sep 2023 16:26:37 GMT", 0.5],
[3, "Fri, 29 Sep 2023 16:26:27 GMT", 0.5],
[3, "Fri, 29 Sep 2023 16:26:37 GMT", 1],
[3, "Fri, 29 Sep 2023 16:26:27 GMT", 1],
[3, "Fri, 29 Sep 2023 16:27:37 GMT", 60],
[3, "Fri, 29 Sep 2023 16:27:38 GMT", 0.5],
[3, "99999999999999999999999999999999999", 0.5],
[3, "Zun, 29 Sep 2023 16:26:27 GMT", 0.5],
[3, "", 0.5],
[2, "", 0.5 * 2.0],
[1, "", 0.5 * 4.0],
[-1100, "", 8], # test large number potentially overflowing
[3, "Fri, 29 Sep 2023 16:27:38 GMT", 1],
[3, "99999999999999999999999999999999999", 1],
[3, "Zun, 29 Sep 2023 16:26:27 GMT", 1],
[3, "", 1],
[2, "", 1 * 2.0],
[1, "", 1 * 4.0],
[-1100, "", 10], # test large number potentially overflowing
],
)
@mock.patch("time.time", mock.MagicMock(return_value=1696004797))
Expand All @@ -704,7 +704,7 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
headers = httpx.Headers({"retry-after": retry_after})
options = FinalRequestOptions(method="get", url="/foo", max_retries=3)
calculated = client._calculate_retry_timeout(remaining_retries, options, headers)
assert calculated == pytest.approx(timeout, 0.5 * 0.875) # pyright: ignore[reportUnknownMemberType]
assert calculated == pytest.approx(timeout, 1 * 0.875) # pyright: ignore[reportUnknownMemberType]

@mock.patch("julep._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
@pytest.mark.respx(base_url=base_url)
Expand Down Expand Up @@ -855,7 +855,7 @@ def test_copy_default_options(self) -> None:
# options that have a default are overridden correctly
copied = self.client.copy(max_retries=7)
assert copied.max_retries == 7
assert self.client.max_retries == 2
assert self.client.max_retries == 5

copied2 = copied.copy(max_retries=6)
assert copied2.max_retries == 6
Expand Down Expand Up @@ -1465,21 +1465,21 @@ class Model(BaseModel):
"remaining_retries,retry_after,timeout",
[
[3, "20", 20],
[3, "0", 0.5],
[3, "-10", 0.5],
[3, "0", 1],
[3, "-10", 1],
[3, "60", 60],
[3, "61", 0.5],
[3, "61", 1],
[3, "Fri, 29 Sep 2023 16:26:57 GMT", 20],
[3, "Fri, 29 Sep 2023 16:26:37 GMT", 0.5],
[3, "Fri, 29 Sep 2023 16:26:27 GMT", 0.5],
[3, "Fri, 29 Sep 2023 16:26:37 GMT", 1],
[3, "Fri, 29 Sep 2023 16:26:27 GMT", 1],
[3, "Fri, 29 Sep 2023 16:27:37 GMT", 60],
[3, "Fri, 29 Sep 2023 16:27:38 GMT", 0.5],
[3, "99999999999999999999999999999999999", 0.5],
[3, "Zun, 29 Sep 2023 16:26:27 GMT", 0.5],
[3, "", 0.5],
[2, "", 0.5 * 2.0],
[1, "", 0.5 * 4.0],
[-1100, "", 8], # test large number potentially overflowing
[3, "Fri, 29 Sep 2023 16:27:38 GMT", 1],
[3, "99999999999999999999999999999999999", 1],
[3, "Zun, 29 Sep 2023 16:26:27 GMT", 1],
[3, "", 1],
[2, "", 1 * 2.0],
[1, "", 1 * 4.0],
[-1100, "", 10], # test large number potentially overflowing
],
)
@mock.patch("time.time", mock.MagicMock(return_value=1696004797))
Expand All @@ -1490,7 +1490,7 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
headers = httpx.Headers({"retry-after": retry_after})
options = FinalRequestOptions(method="get", url="/foo", max_retries=3)
calculated = client._calculate_retry_timeout(remaining_retries, options, headers)
assert calculated == pytest.approx(timeout, 0.5 * 0.875) # pyright: ignore[reportUnknownMemberType]
assert calculated == pytest.approx(timeout, 1 * 0.875) # pyright: ignore[reportUnknownMemberType]

@mock.patch("julep._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
@pytest.mark.respx(base_url=base_url)
Expand Down

0 comments on commit ff985bb

Please sign in to comment.