From cc62389e700a89ff5c3efb04dbe7d3aae076b895 Mon Sep 17 00:00:00 2001 From: Ahtisham Shahid Date: Tue, 2 Jul 2024 14:09:01 +0500 Subject: [PATCH] fix: updated info logs to debug (#35050) --- .../core/djangoapps/notifications/filters.py | 17 +++++++++-------- openedx/core/djangoapps/notifications/tasks.py | 18 +++++------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/openedx/core/djangoapps/notifications/filters.py b/openedx/core/djangoapps/notifications/filters.py index da9642811c8..804a9f98d76 100644 --- a/openedx/core/djangoapps/notifications/filters.py +++ b/openedx/core/djangoapps/notifications/filters.py @@ -64,7 +64,7 @@ def filter_audit_expired_users_with_no_role(self, user_ids, course) -> list: access_duration = get_expected_duration(course.id) course_time_limit = CourseDurationLimitConfig.current(course_key=course.id) if not verified_mode: - logger.info( + logger.debug( "NotificationFilter: Course %s does not have a verified mode, so no users will be filtered out", course.id, ) @@ -81,11 +81,12 @@ def filter_audit_expired_users_with_no_role(self, user_ids, course) -> list: if course_time_limit.enabled_for_course(course.id): enrollments = enrollments.filter(created__gte=course_time_limit.enabled_as_of) - logger.info("NotificationFilter: Number of audit enrollments for course %s: %s", course.id, enrollments.count()) + logger.debug("NotificationFilter: Number of audit enrollments for course %s: %s", course.id, + enrollments.count()) for enrollment in enrollments: if enrollment.user_id in users_with_course_role or enrollment.user_id in users_with_forum_roles: - logger.info( + logger.debug( "NotificationFilter: User %s has a course or forum role for course %s, so they will not be " "filtered out", enrollment.user_id, @@ -94,11 +95,11 @@ def filter_audit_expired_users_with_no_role(self, user_ids, course) -> list: continue content_availability_date = max(enrollment.created, course.start) expiration_date = content_availability_date + access_duration - logger.info("NotificationFilter: content_availability_date: %s and access_duration: %s", - content_availability_date, access_duration - ) + logger.debug("NotificationFilter: content_availability_date: %s and access_duration: %s", + content_availability_date, access_duration + ) if expiration_date and timezone.now() > expiration_date: - logger.info("User %s has expired audit access to course %s", enrollment.user_id, course.id) + logger.debug("User %s has expired audit access to course %s", enrollment.user_id, course.id) user_ids.remove(enrollment.user_id) return user_ids @@ -110,7 +111,7 @@ def apply_filters(self, user_ids, course_key, notification_type) -> list: applicable_filters = notification_config.get('filters', []) course = modulestore().get_course(course_key) for filter_name in applicable_filters: - logger.info( + logger.debug( "NotificationFilter: Applying filter %s for notification type %s", filter_name, notification_type, diff --git a/openedx/core/djangoapps/notifications/tasks.py b/openedx/core/djangoapps/notifications/tasks.py index 4fcec36214a..75ae61a8147 100644 --- a/openedx/core/djangoapps/notifications/tasks.py +++ b/openedx/core/djangoapps/notifications/tasks.py @@ -38,12 +38,11 @@ def create_course_notification_preferences_for_courses(self, course_ids): """ This task creates Course Notification Preferences for users in courses. """ - logger.info('Running task create_course_notification_preferences') newly_created = 0 for course_id in course_ids: enrollments = CourseEnrollment.objects.filter(course_id=course_id, is_active=True) - logger.info(f'Found {enrollments.count()} enrollments for course {course_id}') - logger.info(f'Creating Course Notification Preferences for course {course_id}') + logger.debug(f'Found {enrollments.count()} enrollments for course {course_id}') + logger.debug(f'Creating Course Notification Preferences for course {course_id}') for enrollment in enrollments: _, created = CourseNotificationPreference.objects.get_or_create( user=enrollment.user, course_id=course_id @@ -51,11 +50,10 @@ def create_course_notification_preferences_for_courses(self, course_ids): if created: newly_created += 1 - logger.info( + logger.debug( f'CourseNotificationPreference back-fill completed for course {course_id}.\n' f'Newly created course preferences: {newly_created}.\n' ) - logger.info('Completed task create_course_notification_preferences') @shared_task(ignore_result=True) @@ -81,7 +79,6 @@ def delete_notifications(kwargs): ) delete_count, _ = delete_queryset.delete() total_deleted += delete_count - logger.info(f'Deleted in batch {delete_count}') logger.info(f'Total deleted: {total_deleted}') @@ -93,7 +90,6 @@ def delete_expired_notifications(): """ batch_size = settings.EXPIRED_NOTIFICATIONS_DELETE_BATCH_SIZE expiry_date = datetime.now(UTC) - timedelta(days=settings.NOTIFICATIONS_EXPIRY) - logger.info(f'Deleting expired notifications with batch size: {batch_size}') start_time = datetime.now() total_deleted = 0 delete_count = None @@ -109,7 +105,6 @@ def delete_expired_notifications(): delete_count, _ = delete_queryset.delete() total_deleted += delete_count time_elapsed = datetime.now() - batch_start_time - logger.info(f'{delete_count} Notifications deleted in current batch in {time_elapsed} seconds.') time_elapsed = datetime.now() - start_time logger.info(f'{total_deleted} Notifications deleted in {time_elapsed} seconds.') @@ -137,9 +132,9 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c generated_notification_audience = [] for batch_user_ids in get_list_in_batches(user_ids, batch_size): - logger.info(f'Sending notifications to {len(batch_user_ids)} users in {course_key}') + logger.debug(f'Sending notifications to {len(batch_user_ids)} users in {course_key}') batch_user_ids = NotificationFilter().apply_filters(batch_user_ids, course_key, notification_type) - logger.info(f'After applying filters, sending notifications to {len(batch_user_ids)} users in {course_key}') + logger.debug(f'After applying filters, sending notifications to {len(batch_user_ids)} users in {course_key}') # check if what is preferences of user and make decision to send notification or not preferences = CourseNotificationPreference.objects.filter( @@ -186,8 +181,6 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c notification_content = notification_objects[0].content if notifications_generated: - logger.info(f'Temp: Notifications generated for {len(generated_notification_audience)} out of ' - f'{len(user_ids)} users - {app_name} - {notification_type} - {course_key}.') notification_generated_event( generated_notification_audience, app_name, notification_type, course_key, content_url, notification_content, sender_id=sender_id @@ -227,7 +220,6 @@ def create_notification_pref_if_not_exists(user_ids: List, preferences: List, co user_id=user_id, course_id=course_id, )) - logger.info('Creating new notification preference for user because it does not exist.') if new_preferences: # ignoring conflicts because it is possible that preference is already created by another process # conflicts may arise because of constraint on user_id and course_id fields in model