Skip to content

Commit

Permalink
fix: logging/refactoring for ENT-7458
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Jul 25, 2023
1 parent 5e6c753 commit f19eb4f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
5 changes: 5 additions & 0 deletions enterprise_catalog/apps/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,11 @@ def index_content_keys_in_algolia(content_keys, algolia_client): # pylint: disa
# iterate over courses, programs and pathways and add their metadata to the list of objects to be indexed
for metadata in filtered_content_metadata:
content_key = metadata.content_key
# TODO: remove when https://2u-internal.atlassian.net/browse/ENT-7458 is resolved
if 'GTx+MGT6203x' in content_key:
logger.info(

Check warning on line 667 in enterprise_catalog/apps/api/tasks.py

View check run for this annotation

Codecov / codecov/patch

enterprise_catalog/apps/api/tasks.py#L667

Added line #L667 was not covered by tests
f'[ENT-7458] {content_key} will be added to Algolia index'
)
# Check if we've indexed the course recently
# (programs/pathways are indexed every time regardless of last indexing)
if _was_recently_indexed(content_key) and metadata.content_type not in [PROGRAM, LEARNER_PATHWAY]:
Expand Down
42 changes: 34 additions & 8 deletions enterprise_catalog/apps/catalog/algolia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,43 @@ def _should_index_course(course_metadata):
advertised_course_run_uuid,
)

if advertised_course_run is None:
return False
# We define a series of no-arg functions, each of which has the property that,
# if it returns true, means we should *not* index this record.
def no_advertised_course_run_checker():
return advertised_course_run is None

if not is_course_run_active(advertised_course_run):
return False
def no_owners_checker():
return len(course_json_metadata.get('owners') or []) < 1

if _has_enroll_by_deadline_passed(course_json_metadata, advertised_course_run):
return False
def run_is_hidden_checker():
return bool(advertised_course_run.get('hidden'))

owners = course_json_metadata.get('owners') or []
return not advertised_course_run.get('hidden') and len(owners) > 0
def course_run_not_active_checker():
return not is_course_run_active(advertised_course_run)

def deadline_passed_checker():
return _has_enroll_by_deadline_passed(course_json_metadata, advertised_course_run)

for should_not_index_function, log_message in (
(no_advertised_course_run_checker, 'no advertised course run'),
(course_run_not_active_checker, 'no course run is active'),
(deadline_passed_checker, 'enroll by deadline has passed'),
(run_is_hidden_checker, 'advertised course run is hidden'),
(no_owners_checker, 'no owners exist'),
):
# TODO: remove/simplify logging when https://2u-internal.atlassian.net/browse/ENT-7458 is resolved
should_not_index = should_not_index_function()
if 'GTx+MGT6203x' in course_metadata.content_key:
logger.info(

Check warning on line 190 in enterprise_catalog/apps/catalog/algolia_utils.py

View check run for this annotation

Codecov / codecov/patch

enterprise_catalog/apps/catalog/algolia_utils.py#L190

Added line #L190 was not covered by tests
f'[ENT-7458] {course_metadata.content_key} {log_message} '
f'checker has should_not_index={should_not_index}'
)

if should_not_index:
logger.info(f'[ENT-7458] Should not index {course_metadata.content_key}, {log_message}')
return False

return True


def _has_enroll_by_deadline_passed(course_json_metadata, advertised_course_run):
Expand Down

0 comments on commit f19eb4f

Please sign in to comment.