diff --git a/api_retry/util.py b/api_retry/util.py index 5a99f7f..993a779 100644 --- a/api_retry/util.py +++ b/api_retry/util.py @@ -58,10 +58,10 @@ def api_call_with_retries( :type subscription: string :param method: Request method that should be used (e.g. "GET", "PUT") :type method: string - :param payload: Optional dictionary for sending in the request body + :param payload: Dictionary to include in the request body :type payload: Dictionary with string keys or None, optional :param max_req_attempts: Number of request attempts to make before logging an error - :type max_req_attempts: int + :type max_req_attempts: int, optional :return: Either a Response object or None :rtype: Response or None """ diff --git a/config/.env.sample b/config/.env.sample index 62ec137..18b978b 100644 --- a/config/.env.sample +++ b/config/.env.sample @@ -6,6 +6,9 @@ API_DIR_URL= API_DIR_CLIENT_ID= API_DIR_SECRET= +# Number of attempts to make for a unique Canvas data request before stopping +MAX_REQ_ATTEMPTS=3 + # Application Database # Provided values are for database managed by docker-compose DB_NAME=placement_exams_local diff --git a/pe/orchestration.py b/pe/orchestration.py index 48eb778..faf7b95 100644 --- a/pe/orchestration.py +++ b/pe/orchestration.py @@ -1,5 +1,5 @@ # standard libraries -import json, logging +import json, logging, os from datetime import datetime, timedelta from typing import Any, Dict, List, Union @@ -20,6 +20,8 @@ LOGGER = logging.getLogger(__name__) +MAX_REQ_ATTEMPTS = int(os.getenv('MAX_REQ_ATTEMPTS', '3')) + class ScoresOrchestration: """ @@ -86,7 +88,8 @@ def get_sub_dicts_for_exam(self, page_size: int = 50) -> List[Dict[str, Any]]: get_subs_url, CANVAS_SCOPE, 'GET', - next_params + next_params, + MAX_REQ_ATTEMPTS ) if response is None: LOGGER.info('api_call_with_retries failed to get a response; no more data will be collected')