fix: adding some logging and exceptions to further investigation into discovery load (#32267)
This commit is contained in:
@@ -825,6 +825,8 @@ def get_instructors(course_run, marketing_root_url):
|
||||
"""
|
||||
Get course instructors.
|
||||
"""
|
||||
if course_run is None:
|
||||
raise ValueError("missing course_run")
|
||||
instructors = []
|
||||
staff = course_run.get('staff', [])
|
||||
for instructor in staff:
|
||||
|
||||
@@ -78,7 +78,8 @@ def send_course_enrollment_email(
|
||||
course_key = CourseKey.from_string(course_id)
|
||||
if not course_ended:
|
||||
course_date_blocks = get_course_dates_for_email(user, course_key, request=None)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
log.exception(err)
|
||||
is_course_date_missing = True
|
||||
|
||||
canvas_entry_properties.update(
|
||||
@@ -88,11 +89,17 @@ def send_course_enrollment_email(
|
||||
}
|
||||
)
|
||||
|
||||
if course_id is None:
|
||||
raise ValueError('missing course_id')
|
||||
|
||||
try:
|
||||
course_uuid = get_course_uuid_for_course(course_id)
|
||||
if course_uuid is None:
|
||||
raise ValueError('missing course_uuid')
|
||||
owners = get_owners_for_course(course_uuid=course_uuid) or [{}]
|
||||
course_run = get_course_run_details(course_id, course_run_fields)
|
||||
|
||||
if course_run is None:
|
||||
raise ValueError('missing course_run')
|
||||
marketing_root_url = settings.MKTG_URLS.get("ROOT")
|
||||
instructors = get_instructors(course_run, marketing_root_url)
|
||||
enrollment_count = int(course_run.get("enrollment_count")) if course_run.get("enrollment_count") else 0
|
||||
@@ -111,9 +118,9 @@ def send_course_enrollment_email(
|
||||
"partner_image_url": owners[0].get("logo_image_url") or "",
|
||||
}
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
is_course_run_missing = True
|
||||
log.info(f"[Course Enrollment] Course run call failed for user: {user_id} course: {course_id}")
|
||||
log.warning(f"[Course Enrollment] Course run call failed for user: {user_id} course: {course_id} err: {err}")
|
||||
|
||||
if is_course_run_missing or is_course_date_missing:
|
||||
segment_properties = {
|
||||
|
||||
@@ -448,6 +448,8 @@ def get_course_runs():
|
||||
|
||||
|
||||
def get_course_runs_for_course(course_uuid): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if course_uuid is None:
|
||||
raise ValueError('missing course_uuid')
|
||||
user, catalog_integration = check_catalog_integration_and_get_user(error_message_field='Course runs')
|
||||
if user:
|
||||
cache_key = f"{catalog_integration.CACHE_KEY}.course.{course_uuid}.course_runs"
|
||||
@@ -468,6 +470,8 @@ def get_course_runs_for_course(course_uuid): # lint-amnesty, pylint: disable=mi
|
||||
|
||||
|
||||
def get_owners_for_course(course_uuid): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if course_uuid is None:
|
||||
raise ValueError("missing course_uuid")
|
||||
user, catalog_integration = check_catalog_integration_and_get_user(error_message_field='Owners')
|
||||
if user:
|
||||
cache_key = f"{catalog_integration.CACHE_KEY}.course.{course_uuid}.course_runs"
|
||||
@@ -498,6 +502,8 @@ def get_course_uuid_for_course(course_run_key):
|
||||
Returns:
|
||||
UUID: Course UUID and None if it was not retrieved.
|
||||
"""
|
||||
if course_run_key is None:
|
||||
raise ValueError("missing course_run_key")
|
||||
user, catalog_integration = check_catalog_integration_and_get_user(error_message_field='Course UUID')
|
||||
if user:
|
||||
api_client = get_catalog_api_client(user)
|
||||
@@ -611,6 +617,8 @@ def get_course_run_details(course_run_key, fields):
|
||||
Returns:
|
||||
dict with language, start date, end date, and max_effort details about specified course run
|
||||
"""
|
||||
if course_run_key is None:
|
||||
raise ValueError("missing course_run_key")
|
||||
course_run_details = {}
|
||||
user, catalog_integration = check_catalog_integration_and_get_user(
|
||||
error_message_field=f'Data for course_run {course_run_key}'
|
||||
|
||||
Reference in New Issue
Block a user