app/workers/mails/digest_job.rb
# Running the digest job will take some time to complete.
# Within this timeframe, new notifications might come in. Upon notification creation
# a job is scheduled unless there is no prior digest notification that is not yet read (read_mail_digest: true).
# If we were to only set the read_mail_digest state at the end of the mail rendering an edge case of the following
# would lead to digest not being sent or at least sent unduly late:
# * Job starts and fetches the notifications for rendering. We need to fetch all notifications to be rendered to
#   order them as desired.
# * Notification is created. Because there are unhandled digest notifications no job is scheduled.
# * The above can happen repeatedly.
# * Job ends.
# * No new notification is generated.
#
# A new job would then only be scheduled upon the creation of a new digest notification which (as unlikely as that is)
# might only happen after some days have gone by.
#
# Because we mark the notifications as read even though they in fact aren't, we do it in a transaction
# so that the change is rolled back in case of an error.
Running the digest job will take some time to complete.
Within this timeframe, new notifications might come in. Upon notification creation
a job is scheduled unless there is no prior digest notification that is not yet read (read_mail_digest: true).
If we were to only set the read_mail_digest state at the end of the mail rendering an edge case of the following
would lead to digest not being sent or at least sent unduly late:
Job starts and fetches the notifications for rendering. We need to fetch all notifications to be rendered to
order them as desired.
Notification is created. Because there are unhandled digest notifications no job is scheduled.
The above can happen repeatedly.
Job ends.
No new notification is generated.

A new job would then only be scheduled upon the creation of a new digest notification which (as unlikely as that is)
might only happen after some days have gone by.

Because we mark the notifications as read even though they in fact aren't, we do it in a transaction
so that the change is rolled back in case of an error.
Running the digest job will take some time to complete . Within this timeframe new notifications might come in . Upon notification creation a job is scheduled unless there is no prior digest notification that is not yet read ( read_mail_digest : true ) . If we were to only set the read_mail_digest state at the end of the mail rendering an edge case of the following would lead to digest not being sent or at least sent unduly late : Job starts and fetches the notifications for rendering . We need to fetch all notifications to be rendered to order them as desired . Notification is created . Because there are unhandled digest notifications no job is scheduled . The above can happen repeatedly . Job ends . No new notification is generated . A new job would then only be scheduled upon the creation of a new digest notification which ( as unlikely as that is ) might only happen after some days have gone by . Because we mark the notifications as read even though they in fact aren ' t we do it in a transaction so that the change is rolled back in case of an error .
def with_marked_notifications(notification_ids)
    Notification.transaction do
      mark_notifications_read(notification_ids)
      yield
    end
  end
def with_marked_notifications ( notification_ids ) Notification . transaction do mark_notifications_read ( notification_ids ) yield end end
Running the digest job will take some time to complete.
Running the digest job will take some time to complete .
notification_ids