Skip to content

Commit

Permalink
Full timeout support (#255)
Browse files Browse the repository at this point in the history
* timeout support throughout astrapy/core layer

* test for timeout behaviour to db/collection, sync/async, read/write

* full max_time_ms support for all single-request methods of db and coll

* cursors, find and their distinct() support timeout

* docstring for DataAPITimeoutException

* insert_many, delete_many, update_many support method-wide timeout

* add sort to core update_one, delete_one, delete_one_by_predicate; add sort to idiomatic replace_one, update_one, delete_one + tests

* align signatures and make most params kwonly across collection/asynccollection/database/asyncdatabase

* operation classes bear the full method signatures (except timeout)

* bulk_write supports timeout + tests

* fix method name in unit test

* enable update_many paginated tests in prod after deploy

* more stringent values to ensure timeout tests pass
  • Loading branch information
hemidactylus authored Mar 18, 2024
1 parent e6a31db commit 173c59b
Show file tree
Hide file tree
Showing 18 changed files with 2,394 additions and 309 deletions.
296 changes: 259 additions & 37 deletions astrapy/collection.py

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion astrapy/core/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import httpx
from typing import Any, Dict, Optional, cast
from typing import Any, Dict, Optional, Union, cast

from astrapy.core.core_types import API_RESPONSE
from astrapy.core.utils import amake_request, make_request
Expand Down Expand Up @@ -32,6 +32,7 @@ def raw_api_request(
path: Optional[str],
caller_name: Optional[str],
caller_version: Optional[str],
timeout: Optional[Union[httpx.Timeout, float]],
) -> httpx.Response:
return make_request(
client=client,
Expand All @@ -44,6 +45,7 @@ def raw_api_request(
path=path,
caller_name=caller_name,
caller_version=caller_version,
timeout=timeout,
)


Expand Down Expand Up @@ -82,6 +84,7 @@ def api_request(
skip_error_check: bool,
caller_name: Optional[str],
caller_version: Optional[str],
timeout: Optional[Union[httpx.Timeout, float]],
) -> API_RESPONSE:
raw_response = raw_api_request(
client=client,
Expand All @@ -94,6 +97,7 @@ def api_request(
path=path,
caller_name=caller_name,
caller_version=caller_version,
timeout=timeout,
)
raw_response.raise_for_status()
return process_raw_api_response(
Expand All @@ -113,6 +117,7 @@ async def async_raw_api_request(
path: Optional[str],
caller_name: Optional[str],
caller_version: Optional[str],
timeout: Optional[Union[httpx.Timeout, float]],
) -> httpx.Response:
return await amake_request(
client=client,
Expand All @@ -125,6 +130,7 @@ async def async_raw_api_request(
path=path,
caller_name=caller_name,
caller_version=caller_version,
timeout=timeout,
)


Expand Down Expand Up @@ -163,6 +169,7 @@ async def async_api_request(
skip_error_check: bool,
caller_name: Optional[str],
caller_version: Optional[str],
timeout: Optional[Union[httpx.Timeout, float]],
) -> API_RESPONSE:
raw_response = await async_raw_api_request(
client=client,
Expand All @@ -175,6 +182,7 @@ async def async_api_request(
path=path,
caller_name=caller_name,
caller_version=caller_version,
timeout=timeout,
)
raw_response.raise_for_status()
return await async_process_raw_api_response(
Expand Down
Loading

0 comments on commit 173c59b

Please sign in to comment.