Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import random
import re
import requests
from rest_framework import status
from rest_framework.exceptions import APIException
import string # pylint: disable=deprecated-module
import urlparse

Expand Down Expand Up @@ -1357,7 +1359,26 @@ def advanced_settings_handler(request, course_key_string):
course_module.specialization_slug
)
)
r = requests.get(url)
try:
r = requests.get(url=url, timeout=settings.EDRAAK_PROGRAMS_API_TIMEOUT)
except requests.exceptions.Timeout:
raise APIException(
{
"status_code": status.HTTP_503_SERVICE_UNAVAILABLE,
"developer_message": "Programs specialization API have timed out."
},
code=status.HTTP_503_SERVICE_UNAVAILABLE,
)
except Exception:
log.exception('Something went wrong with the programs specialization API')
raise APIException(
{
"status_code": status.HTTP_500_INTERNAL_SERVER_ERROR,
"developer_message": "Programs specialization didn't respond correctly."
},
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)

if r.status_code != requests.codes.ok:
return JsonResponseBadRequest([
{
Expand Down
3 changes: 3 additions & 0 deletions cms/envs/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@

PROGS_URLS = ENV_TOKENS.get('PROGS_URLS', PROGS_URLS)

# API Calls Timeout
EDRAAK_PROGRAMS_API_TIMEOUT = ENV_TOKENS.get('EDRAAK_PROGRAMS_API_TIMEOUT', 3)

################ PUSH NOTIFICATIONS ###############

PARSE_KEYS = AUTH_TOKENS.get("PARSE_KEYS", {})
Expand Down
4 changes: 4 additions & 0 deletions cms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@

COUNTRIES_FIRST = [] # Turned off here to pass edx tests

EDRAAK_PROGRAMS_API_TIMEOUT = 4

EDRAAK_MARKETING_API_TIMEOUT = 4

######### custom courses #########
INSTALLED_APPS.append('openedx.core.djangoapps.ccxcon.apps.CCXConnectorConfig')
FEATURES['CUSTOM_COURSES_EDX'] = True
Expand Down
29 changes: 26 additions & 3 deletions lms/djangoapps/course_api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from django.conf import settings
from edxmako.shortcuts import marketing_link
import logging
from rest_framework import status
from rest_framework.exceptions import APIException


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -53,9 +56,29 @@ def get_marketing_data(course_key, language):
marketing_root_format = marketing_link('COURSE_DETAILS_API_FORMAT')
url = marketing_root_format.format(course_id=course_key)

response = requests.get(url=url, headers={
'Accept-Language': language,
})
try:
response = requests.get(
url=url,
headers={'Accept-Language': language},
timeout=settings.EDRAAK_MARKETING_API_TIMEOUT
)
except requests.exceptions.Timeout:
raise APIException(
{
"status_code": status.HTTP_503_SERVICE_UNAVAILABLE,
"developer_message": "Marketing courses API have timed out."
},
code=status.HTTP_503_SERVICE_UNAVAILABLE,
)
except Exception:
log.exception('Something went wrong with the marketing courses API')
raise APIException(
{
"status_code": status.HTTP_500_INTERNAL_SERVER_ERROR,
"developer_message": "Marketing courses didn't respond correctly."
},
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)

if response.status_code != 200:
log.warning('Could not fetch the marketing details from the API. course_key=[%s], status_code=[%s], url=[%s].',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ def test_language_header_and_url(self, course_key):
with mock_requests_get() as mocked_get:
helpers.get_marketing_data(course_key, 'eo')
self.assertEquals(mocked_get.call_count, 1) # Should be called once
mocked_get.assert_called_once_with(url=expected_url, headers={'Accept-Language': 'eo'})
mocked_get.assert_called_once_with(
url=expected_url,
headers={'Accept-Language': 'eo'},
timeout=4
)

def test_valid_response(self):
with mock_requests_get(status_code=200, body_json={'name': 'My Course'}):
Expand Down
3 changes: 3 additions & 0 deletions lms/envs/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@
EDRAAK_AUTH_REDIRECT_ORIGINS_WHITELIST = ENV_TOKENS.get("EDRAAK_AUTH_REDIRECT_ORIGINS_WHITELIST", [])
EDRAAK_AUTH_REDIRECT_REGX_ORIGINS = ENV_TOKENS.get("EDRAAK_AUTH_REDIRECT_REGX_ORIGINS", [])

# API Calls Timeout
EDRAAK_MARKETING_API_TIMEOUT = ENV_TOKENS.get('EDRAAK_MARKETING_API_TIMEOUT', 3)

##### ACCOUNT LOCKOUT DEFAULT PARAMETERS #####
MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED = ENV_TOKENS.get("MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED", 5)
MAX_FAILED_LOGIN_ATTEMPTS_LOCKOUT_PERIOD_SECS = ENV_TOKENS.get("MAX_FAILED_LOGIN_ATTEMPTS_LOCKOUT_PERIOD_SECS", 15 * 60)
Expand Down
2 changes: 2 additions & 0 deletions lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@

FEATURES['ENABLE_EDRAAK_LOGISTRATION'] = False # Disabled in tests by default

EDRAAK_MARKETING_API_TIMEOUT = 4

COURSE_CATALOG_API_URL = 'https://catalog.example.com/api/v1'

COMPREHENSIVE_THEME_DIRS = [REPO_ROOT / "themes", REPO_ROOT / "common/test"]
Expand Down
20 changes: 11 additions & 9 deletions lms/static/js/instructor_dashboard/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,17 @@
ths, arguments
);
};
this.$running_tasks_section = findAndAssert(this.$section, '.running-tasks-section');
this.$table_running_tasks = findAndAssert(this.$section, '.running-tasks-table');
this.$no_tasks_message = findAndAssert(this.$section, '.no-pending-tasks-message');
if (this.$table_running_tasks.length) {
TASK_LIST_POLL_INTERVAL = 20000;
this.reload_running_tasks_list();
this.task_poller = new IntervalManager(TASK_LIST_POLL_INTERVAL, function() {
return ths.reload_running_tasks_list();
});
if (this.$section.find('.running-tasks-container').length) {
this.$running_tasks_section = findAndAssert(this.$section, '.running-tasks-section');
this.$table_running_tasks = findAndAssert(this.$section, '.running-tasks-table');
this.$no_tasks_message = findAndAssert(this.$section, '.no-pending-tasks-message');
if (this.$table_running_tasks.length) {
TASK_LIST_POLL_INTERVAL = 20000;
this.reload_running_tasks_list();
this.task_poller = new IntervalManager(TASK_LIST_POLL_INTERVAL, function () {
return ths.reload_running_tasks_list();
});
}
}
}

Expand Down