discourse/app/jobs/scheduled/bookmark_reminder_notifications.rb
Bianca Nenciu 30f3e78834
FIX: Reset last sent for existent bookmarks (#16202)
The meaning of reminder_at and reminder_last_sent_at changed after
commit 6d422a8033. A bookmark reminder
will fire only if reminder_last_sent_at is null, but before that it
fired everytime reminder_at was set. This is no longer true because
sometimes reminder_at continues to exist even after a reminder fired.
2022-03-18 16:31:35 +02:00

28 lines
917 B
Ruby

# frozen_string_literal: true
module Jobs
# Runs periodically to send out bookmark reminders, capped at 300 at a time.
# Any leftovers will be caught in the next run, because the reminder_at column
# is set to NULL once a reminder has been sent.
class BookmarkReminderNotifications < ::Jobs::Scheduled
every 5.minutes
def self.max_reminder_notifications_per_run
@@max_reminder_notifications_per_run ||= 300
@@max_reminder_notifications_per_run
end
def self.max_reminder_notifications_per_run=(max)
@@max_reminder_notifications_per_run = max
end
def execute(args = nil)
bookmarks = Bookmark.pending_reminders.includes(:user).order('reminder_at ASC')
bookmarks.limit(BookmarkReminderNotifications.max_reminder_notifications_per_run).each do |bookmark|
BookmarkReminderNotificationHandler.send_notification(bookmark)
end
end
end
end