mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 19:32:59 +08:00
222c8d9b6a
A bit of a mixed bag, this addresses several edge areas of bookmarks and makes them compatible with polymorphic bookmarks (hidden behind the `use_polymorphic_bookmarks` site setting). The main ones are: * ExportUserArchive compatibility * SyncTopicUserBookmarked job compatibility * Sending different notifications for the bookmark reminders based on the bookmarkable type * Import scripts compatibility * BookmarkReminderNotificationHandler compatibility This PR also refactors the `register_bookmarkable` API so it accepts a class descended from a `BaseBookmarkable` class instead. This was done because we kept having to add more and more lambdas/properties inline and it was very messy, so a factory pattern is cleaner. The classes can be tested independently as well. Some later PRs will address some other areas like the discourse narrative bot, advanced search, reports, and the .ics endpoint for bookmarks.
28 lines
921 B
Ruby
28 lines
921 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.new(bookmark).send_notification
|
|
end
|
|
end
|
|
end
|
|
end
|