Update notification in SendUpcomingNotificationService tracking to create EmailEvent records
Problem
Currently, the SendUpcomingNotificationService tracks sent notifications by updating a timestamp field on the Order model (upcoming_auto_renewal_notified_at). This approach lacks detailed tracking of which notifications were sent, to whom, and when. With our new Notifications::EmailEvent model, we need to update the service to create proper EmailEvent records for better tracking and analysis.
Proposal
Modify the SendUpcomingNotificationService to create Notifications::EmailEvent records when emails are sent. This will involve:
- Updating the
notification_successfulmethod to create an EmailEvent record after successfully sending an email - Including relevant metadata such as notification type, recipient, and order details in the EmailEvent record
- Modifying the "already notified" check to use EmailEvent records instead of the timestamp field
- Ensuring proper error handling and logging for EmailEvent creation
Result
- Detailed tracking of all sent notifications in the
EmailEventtable
How will we measure success?
-
EmailEventrecords are created for every notification sent - The records contain accurate information about the notification
- The system correctly prevents duplicate notifications based on
EmailEventrecords