Skip to content

Commit

Permalink
fix: updated goal reminder task
Browse files Browse the repository at this point in the history
  • Loading branch information
AhtishamShahid committed Nov 29, 2024
1 parent 9cade7a commit 393d399
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,26 @@ def _handle_all_goals(self):
log.info('Cleared all reminder statuses')
return

course_goals = CourseGoal.objects.filter(
days_per_week__gt=0, subscribed_to_reminders=True,
).exclude(
reminder_status__email_reminder_sent=True,
course_goals = (
CourseGoal.objects.filter(
days_per_week__gt=0,
subscribed_to_reminders=True,
)
.exclude(
reminder_status__email_reminder_sent=True,
)
.exclude(
course_key__in=CourseOverview.objects.filter(
end__date__lte=sunday_date
).values_list('id', flat=True)
)
.select_related('user')
.order_by('user').iterator()
)
all_goal_course_keys = course_goals.values_list('course_key', flat=True).distinct()
# Exclude all courses whose end dates are earlier than Sunday so we don't send an email about hitting
# a course goal when it may not even be possible.
courses_to_exclude = CourseOverview.objects.filter(
id__in=all_goal_course_keys, end__date__lte=sunday_date
).values_list('id', flat=True)
log.info(f"Processing course goals across {len(all_goal_course_keys)} courses "
+ f"excluding {len(courses_to_exclude)} ended courses")

sent_count = 0
filtered_count = 0
course_goals = course_goals.exclude(course_key__in=courses_to_exclude).select_related('user').order_by('user')
total_goals = len(course_goals)
total_goals = 0

tracker.emit(
'edx.course.goal.email.session_started',
{
Expand All @@ -211,9 +213,9 @@ def _handle_all_goals(self):
'goal_count': total_goals,
}
)
log.info(f'Processing course goals, total goal count {total_goals},'
+ f'timestamp: {datetime.now()}, uuid: {session_id}')

for goal in course_goals:
total_goals += 1
# emulate a request for waffle's benefit
with emulate_http_request(site=Site.objects.get_current(), user=goal.user):
if self.handle_goal(goal, today, sunday_date, monday_date, session_id):
Expand All @@ -224,6 +226,9 @@ def _handle_all_goals(self):
log.info(f'Processing course goals: sent {sent_count} filtered {filtered_count} out of {total_goals},'
+ f'timestamp: {datetime.now()}, uuid: {session_id}')

log.info(f'Processing course goals, total goal count {total_goals},'
+ f'timestamp: {datetime.now()}, uuid: {session_id}')

tracker.emit(
'edx.course.goal.email.session_completed',
{
Expand Down

0 comments on commit 393d399

Please sign in to comment.