Skip to content

Commit

Permalink
feat: adds backoff to enterprise-catalog client calls
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Aug 27, 2024
1 parent c13c560 commit 7c5bf6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 0 additions & 3 deletions docs/decisions/0022-spend-limits-constraint.rst

This file was deleted.

16 changes: 16 additions & 0 deletions enterprise_access/apps/api_client/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Constants for API client
"""
import backoff
from requests.exceptions import ConnectionError as RequestsConnectionError
from requests.exceptions import HTTPError
from requests.exceptions import Timeout as RequestsTimeoutError

# wait_gen references the field in the backoff decorator representing
# the backoff strategy for retries
wait_gen = backoff.expo

exception = (
RequestsConnectionError,
RequestsTimeoutError,
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
API client for enterprise-catalog service.
"""

import backoff
from django.conf import settings

from enterprise_access.apps.api_client.base_oauth import BaseOAuthClient
from enterprise_access.apps.api_client.constants import exception, wait_gen


class EnterpriseCatalogApiClient(BaseOAuthClient):
Expand All @@ -14,6 +15,7 @@ class EnterpriseCatalogApiClient(BaseOAuthClient):
api_base_url = settings.ENTERPRISE_CATALOG_URL + '/api/v1/'
enterprise_catalog_endpoint = api_base_url + 'enterprise-catalogs/'

@backoff.on_exception(wait_gen, exception)
def contains_content_items(self, catalog_uuid, content_ids):
"""
Check whether the specified enterprise catalog contains the given content.
Expand All @@ -31,8 +33,10 @@ def contains_content_items(self, catalog_uuid, content_ids):
response = self.client.get(endpoint, params=query_params)
response.raise_for_status()
response_json = response.json()
print(response_json)
return response_json.get('contains_content_items', False)

@backoff.on_exception(wait_gen, exception)
def catalog_content_metadata(self, catalog_uuid, content_keys, traverse_pagination=True, **kwargs):
"""
Returns a list of requested content metadata records for the given catalog_uuid.
Expand Down Expand Up @@ -68,6 +72,7 @@ def catalog_content_metadata(self, catalog_uuid, content_keys, traverse_paginati
response.raise_for_status()
return response.json()

@backoff.on_exception(wait_gen, exception)
def get_content_metadata_count(self, catalog_uuid):
"""
Returns the count of content metadata for a catalog.
Expand Down

0 comments on commit 7c5bf6c

Please sign in to comment.