Skip to content

Commit

Permalink
Make HTTP request timeout configurable
Browse files Browse the repository at this point in the history
The timeout can be configured using AALTO_SISU_REQUEST_TIMEOUT
settings variable.
  • Loading branch information
PasiSa committed Jun 21, 2023
1 parent d5f3339 commit 633e84c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions aalto_sisu/sis_aalto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import requests
from course.sis import StudentInfoSystem

HTTP_REQUEST_TIMEOUT = 5 # seconds
HTTP_REQUEST_TIMEOUT = 20 # seconds

class SisuAalto(StudentInfoSystem):

def get_instances(self, course: str) -> List[Tuple[str, str]]:
# A+ should handle exceptions properly, so we do not do any special handling here
url=f"{settings.AALTO_SISU_URL_PREFIX}/courseunitrealisations?code={course}&USER_KEY={settings.AALTO_SISU_API_KEY}"
response = requests.get(url, timeout = HTTP_REQUEST_TIMEOUT)
response = requests.get(url, timeout=getattr(settings, 'AALTO_SISU_REQUEST_TIMEOUT', HTTP_REQUEST_TIMEOUT))
response.raise_for_status()

json = response.json()
Expand All @@ -25,7 +25,11 @@ def request_from_enhanced_api(self, id: str) -> dict:
headers = {"X-ApiKey":str(settings.AALTO_SISU_ENHANCED_API_KEY)}
else:
headers = {"X-ApiKey":""}
response = requests.get(url, headers=headers, timeout = HTTP_REQUEST_TIMEOUT)
response = requests.get(
url,
headers=headers,
timeout=getattr(settings, 'AALTO_SISU_REQUEST_TIMEOUT', HTTP_REQUEST_TIMEOUT),
)
response.raise_for_status()

return response.json()[0]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='aalto-sisu',
version='0.3.0',
version='0.4.0',
description='Aalto-SISU plugin for A+ LMS',
long_description=long_description,
keywords='django',
Expand Down

0 comments on commit 633e84c

Please sign in to comment.