2020-03-12 08:16:00 +08:00
|
|
|
# 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
|
2020-11-17 07:08:12 +08:00
|
|
|
@@max_reminder_notifications_per_run ||= 300
|
2020-03-12 08:16:00 +08:00
|
|
|
@@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)
|
2022-03-18 22:31:35 +08:00
|
|
|
bookmarks = Bookmark.pending_reminders.includes(:user).order('reminder_at ASC')
|
2020-03-12 08:16:00 +08:00
|
|
|
bookmarks.limit(BookmarkReminderNotifications.max_reminder_notifications_per_run).each do |bookmark|
|
2022-05-09 07:37:23 +08:00
|
|
|
BookmarkReminderNotificationHandler.new(bookmark).send_notification
|
2020-03-12 08:16:00 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|