Skip to content

Commit

Permalink
feat: added snowflake events for email notifications (#35158)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadadeeltajamul authored Jul 24, 2024
1 parent 188be30 commit ce290db
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions openedx/core/djangoapps/notifications/email/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Events for email notifications
"""
import datetime

from eventtracking import tracker

from common.djangoapps.track import segment
from openedx.core.djangoapps.notifications.base_notification import COURSE_NOTIFICATION_APPS


EMAIL_DIGEST_SENT = "edx.notifications.email_digest"


def send_user_email_digest_sent_event(user, cadence_type, notifications):
"""
Sends tracker and segment email for user email digest
"""
notification_breakdown = {key: 0 for key in COURSE_NOTIFICATION_APPS.keys()}
for notification in notifications:
notification_breakdown[notification.app_name] += 1
event_data = {
"username": user.username,
"email": user.email,
"cadence_type": cadence_type,
"total_notifications_count": len(notifications),
"count_breakdown": notification_breakdown,
"notification_ids": [notification.id for notification in notifications],
"send_at": str(datetime.datetime.now())
}
with tracker.get_tracker().context(EMAIL_DIGEST_SENT, event_data):
tracker.emit(
EMAIL_DIGEST_SENT,
event_data,
)
segment.track(
'None',
EMAIL_DIGEST_SENT,
event_data,
)
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/notifications/email/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Notification,
get_course_notification_preference_config_version
)
from .events import send_user_email_digest_sent_event
from .message_type import EmailNotificationMessageType
from .utils import (
add_headers_to_email_message,
Expand Down Expand Up @@ -101,6 +102,7 @@ def send_digest_email_to_user(user, cadence_type, course_language='en', courses_
).personalize(recipient, course_language, message_context)
message = add_headers_to_email_message(message, message_context)
ace.send(message)
send_user_email_digest_sent_event(user, cadence_type, notifications)
logger.info(f'<Email Cadence> Email sent to {user.username} ==Temp Log==')


Expand Down

0 comments on commit ce290db

Please sign in to comment.