Skip to content

Commit

Permalink
fix: updated info logs to debug (#35050)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhtishamShahid authored Jul 2, 2024
1 parent 06264e7 commit cc62389
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
17 changes: 9 additions & 8 deletions openedx/core/djangoapps/notifications/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
Expand All @@ -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

Expand All @@ -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,
Expand Down
18 changes: 5 additions & 13 deletions openedx/core/djangoapps/notifications/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,22 @@ 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
)
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)
Expand All @@ -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}')


Expand All @@ -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
Expand All @@ -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.')

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc62389

Please sign in to comment.