From df197837cba5e1825728d952d79c0936e5f75bcf Mon Sep 17 00:00:00 2001 From: Mohammad Ahtasham ul Hassan <60315450+aht007@users.noreply.github.com> Date: Mon, 7 Aug 2023 18:01:50 +0500 Subject: [PATCH] fix: remove extras and enhance existing subs logging (#32919) --- .../entitlements/rest_api/v1/views.py | 10 ---------- common/djangoapps/entitlements/tasks.py | 20 +++++++++---------- openedx/core/djangoapps/credentials/utils.py | 8 ++------ 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/common/djangoapps/entitlements/rest_api/v1/views.py b/common/djangoapps/entitlements/rest_api/v1/views.py index 6eaf24c3da..9442dae29c 100644 --- a/common/djangoapps/entitlements/rest_api/v1/views.py +++ b/common/djangoapps/entitlements/rest_api/v1/views.py @@ -565,11 +565,6 @@ class SubscriptionsRevokeVerifiedAccessView(APIView): entitled_course_ids) awarded_cert_course_ids, is_exception = get_courses_completion_status(username, entitled_course_ids) - log.info('B2C_SUBSCRIPTIONS: Got course completion response %s for user [%s] and entitled_course_ids %s', - awarded_cert_course_ids, - username, - entitled_course_ids) - if is_exception: # Trigger the retry task asynchronously log.exception('B2C_SUBSCRIPTIONS: Exception occurred while getting course completion status for user %s ' @@ -580,11 +575,6 @@ class SubscriptionsRevokeVerifiedAccessView(APIView): entitled_course_ids, username)) return - log.info('B2C_SUBSCRIPTIONS: Starting revoke_entitlements_and_downgrade_courses_to_audit for user [%s] and ' - 'awarded_cert_course_ids %s and revocable_entitlement_uuids %s', - username, - awarded_cert_course_ids, - revocable_entitlement_uuids) revoke_entitlements_and_downgrade_courses_to_audit(course_entitlements, username, awarded_cert_course_ids, revocable_entitlement_uuids) diff --git a/common/djangoapps/entitlements/tasks.py b/common/djangoapps/entitlements/tasks.py index 0adb2c3338..0dd8d363dd 100644 --- a/common/djangoapps/entitlements/tasks.py +++ b/common/djangoapps/entitlements/tasks.py @@ -162,6 +162,11 @@ def retry_revoke_subscriptions_verified_access(self, revocable_entitlement_uuids Task to process course access revoke and move to audit. This is called only if call to get_courses_completion_status fails due to any exception. """ + LOGGER.info("B2C_SUBSCRIPTIONS: Running retry_revoke_subscriptions_verified_access for user [%s]," + " entitlement_uuids %s and entitled_course_ids %s", + username, + revocable_entitlement_uuids, + entitled_course_ids) course_entitlements = CourseEntitlement.objects.filter(uuid__in=revocable_entitlement_uuids) course_entitlements = course_entitlements.select_related('user').select_related('enrollment_course_run') if course_entitlements.exists(): @@ -171,22 +176,17 @@ def retry_revoke_subscriptions_verified_access(self, revocable_entitlement_uuids countdown = 2 ** self.request.retries self.retry(countdown=countdown, max_retries=3) except MaxRetriesExceededError: - log.exception( + LOGGER.exception( 'B2C_SUBSCRIPTIONS: Failed to process retry_revoke_subscriptions_verified_access ' 'for user [%s] and entitlement_uuids %s', username, revocable_entitlement_uuids ) return - log.info('B2C_SUBSCRIPTIONS: Starting revoke_entitlements_and_downgrade_courses_to_audit for user [%s] and ' - 'awarded_cert_course_ids %s and revocable_entitlement_uuids %s from retry task', - username, - awarded_cert_course_ids, - revocable_entitlement_uuids) revoke_entitlements_and_downgrade_courses_to_audit(course_entitlements, username, awarded_cert_course_ids, revocable_entitlement_uuids) else: - log.info('B2C_SUBSCRIPTIONS: Entitlements not found for the provided entitlements uuids %s ' - 'for user [%s] duing the retry_revoke_subscriptions_verified_access task', - revocable_entitlement_uuids, - username) + LOGGER.info('B2C_SUBSCRIPTIONS: Entitlements not found for the provided entitlements uuids %s ' + 'for user [%s] duing the retry_revoke_subscriptions_verified_access task', + revocable_entitlement_uuids, + username) diff --git a/openedx/core/djangoapps/credentials/utils.py b/openedx/core/djangoapps/credentials/utils.py index 9e7f61e189..b17b7ffffa 100644 --- a/openedx/core/djangoapps/credentials/utils.py +++ b/openedx/core/djangoapps/credentials/utils.py @@ -148,20 +148,16 @@ def get_courses_completion_status(username, course_run_ids): exc ) return [], True - # Yes, This is course_credentials_data. The key is named status but - # it contains all the courses data from credentials. log.info("Course completion status response for user [%s] for course_run_ids [%s] is [%s]", username, course_run_ids, course_completion_response) + # Yes, This is course_credentials_data. The key is named status but + # it contains all the courses data from credentials. course_credentials_data = course_completion_response.get('status', []) if course_credentials_data is not None: filtered_records = [course_data['course_run']['key'] for course_data in course_credentials_data if course_data['course_run']['key'] in course_run_ids and course_data['status'] == settings.CREDENTIALS_COURSE_COMPLETION_STATE] - log.info("Filtered course completion status response for user [%s] for course_run_ids [%s] is [%s]", - username, - course_run_ids, - filtered_records) return filtered_records, False return [], False