Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logs while importing course #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def validate_course_olx(courselike_key, course_dir, status):
ignore=settings.COURSE_OLX_VALIDATION_IGNORE_LIST,
allowed_xblocks=ALL_ALLOWED_XBLOCKS
)
except Exception: # pylint: disable=broad-except
except Exception as e: # pylint: disable=broad-except

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this changed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added "as e" after Exception to print it. Awais bhai told me LOGGER.Exception prints exception. Restored old code.

LOGGER.exception(f'{log_prefix}: CourseOlx could not be validated')
return olx_is_valid

Expand Down
7 changes: 6 additions & 1 deletion common/lib/xmodule/xmodule/modulestore/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def try_load_course(self, course_dir, course_ids=None, target_course_id=None):
raise exc
finally:
if course_descriptor is None:
pass
if str(target_course_id) == "course-v1:ArbiX+CS101+2014_T3":
logging.info(f"Investigation Log: {target_course_id} : Course Descriptor is None")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be part of the if course_descriptor is None: block. the logs should be immediately after the finally: block.

logging.info(f"Investigation Log: {target_course_id} : {course_descriptor} ") something like this.

elif isinstance(course_descriptor, ErrorBlock):
# Didn't load course. Instead, save the errors elsewhere.
self.errored_courses[course_dir] = errorlog
Expand Down Expand Up @@ -487,6 +488,8 @@ def load_course(self, course_dir, course_ids, tracker, target_course_id=None):
course_id = self.get_id(org, course, url_name)

if course_ids is not None and course_id not in course_ids:
if str(target_course_id) == "course-v1:ArbiX+CS101+2014_T3":
logging.info(f"Investigation Log: {target_course_id} : Course ID not in Course IDs (List)")
return None

def get_policy(usage_id):
Expand Down Expand Up @@ -522,6 +525,8 @@ def get_policy(usage_id):
course_descriptor = system.process_xml(etree.tostring(course_data, encoding='unicode'))
# If we fail to load the course, then skip the rest of the loading steps
if isinstance(course_descriptor, ErrorBlock):
if str(target_course_id) == "course-v1:ArbiX+CS101+2014_T3":
logging.info(f"Investigation Log: {target_course_id} : Course Descriptor is instance of ErrorBlock")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see single quotes here in this file, please use single quotes here too.

return course_descriptor

self.content_importers(system, course_descriptor, course_dir, url_name)
Expand Down
11 changes: 11 additions & 0 deletions common/lib/xmodule/xmodule/modulestore/xml_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ def run_imports(self):
"""
Iterate over the given directories and yield courses.
"""
if str(self.target_id) == "course-v1:ArbiX+CS101+2014_T3":
logging.info(f"Investigation Log: {self.target_id} : Starting run imports")
self.preflight()
for courselike_key in self.xml_module_store.modules.keys():
try:
Expand All @@ -558,12 +560,18 @@ def run_imports(self):

# Import all static pieces.
self.import_static(data_path, dest_id)
if str(self.target_id) == "course-v1:ArbiX+CS101+2014_T3":
logging.info(f"Investigation Log: {self.target_id} : Import Static Successful")

# Import asset metadata stored in XML.
self.import_asset_metadata(data_path, dest_id)
if str(self.target_id) == "course-v1:ArbiX+CS101+2014_T3":
logging.info(f"Investigation Log: {self.target_id} : Import Asset Metadata Successful")

# Import all children
self.import_children(source_courselike, courselike, courselike_key, dest_id)
if str(self.target_id) == "course-v1:ArbiX+CS101+2014_T3":
logging.info(f"Investigation Log: {self.target_id} : Import Children Successful")

# This bulk operation wraps all the operations to populate the draft branch with any items
# from the /drafts subdirectory.
Expand All @@ -573,6 +581,9 @@ def run_imports(self):
with self.store.bulk_operations(dest_id):
# Import all draft items into the courselike.
courselike = self.import_drafts(courselike, courselike_key, data_path, dest_id)
if str(self.target_id) == "course-v1:ArbiX+CS101+2014_T3":
logging.info(f"Investigation Log: {self.target_id} : Import Draft Successful")


yield courselike

Expand Down