Skip to content

Commit

Permalink
feat: adds backoff to enterprise-catalog client calls (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 authored Sep 3, 2024
1 parent d4bf7dd commit 8fbda7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions enterprise_access/apps/api_client/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Constants for API client
"""
from requests.exceptions import ConnectionError as RequestsConnectionError
from requests.exceptions import Timeout as RequestsTimeoutError

autoretry_for_exceptions = (
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 autoretry_for_exceptions


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=backoff.expo, exception=autoretry_for_exceptions)
def contains_content_items(self, catalog_uuid, content_ids):
"""
Check whether the specified enterprise catalog contains the given content.
Expand All @@ -33,6 +35,7 @@ def contains_content_items(self, catalog_uuid, content_ids):
response_json = response.json()
return response_json.get('contains_content_items', False)

@backoff.on_exception(wait_gen=backoff.expo, exception=autoretry_for_exceptions)
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 +71,7 @@ def catalog_content_metadata(self, catalog_uuid, content_keys, traverse_paginati
response.raise_for_status()
return response.json()

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

0 comments on commit 8fbda7f

Please sign in to comment.