Skip to content

Commit

Permalink
Merge pull request #49 from ssciolla/issue-32-make-req-num-configurable
Browse files Browse the repository at this point in the history
Make maximum request attempts configurable (#32)
  • Loading branch information
ssciolla committed Nov 3, 2020
2 parents b0171b8 + 1eb4dd6 commit 5a6825b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions api_retry/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
3 changes: 3 additions & 0 deletions config/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pe/orchestration.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -20,6 +20,8 @@

LOGGER = logging.getLogger(__name__)

MAX_REQ_ATTEMPTS = int(os.getenv('MAX_REQ_ATTEMPTS', '3'))


class ScoresOrchestration:
"""
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 5a6825b

Please sign in to comment.