Skip to content

Commit

Permalink
Add optional callback into HTTPClient.request
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt committed Nov 4, 2023
1 parent 69b1b0b commit ed91068
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cognite/client/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from cognite.client.config import global_config
from cognite.client.exceptions import CogniteConnectionError, CogniteConnectionRefused, CogniteReadTimeout
from cognite.client.utils._api_usage import RequestDetails


class BlockAll(cookiejar.CookiePolicy):
Expand Down Expand Up @@ -114,6 +115,10 @@ def request(self, method: str, url: str, **kwargs: Any) -> requests.Response:
while True:
try:
res = self._do_request(method=method, url=url, **kwargs)
if global_config.usage_tracking_callback:
# We use the RequestDetails as an indirection to avoid the user mutating the request:
global_config.usage_tracking_callback(RequestDetails.from_response(res))

last_status = res.status_code
retry_tracker.status += 1
if not retry_tracker.should_retry(status_code=last_status):
Expand Down

0 comments on commit ed91068

Please sign in to comment.