mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 17:23:44 +08:00
25 lines
799 B
Ruby
25 lines
799 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class ProcessShelvedNotifications < ::Jobs::Scheduled
|
|
every 5.minutes
|
|
|
|
def execute(args)
|
|
sql = <<~SQL
|
|
SELECT sn.id FROM shelved_notifications as sn
|
|
INNER JOIN notifications AS notification ON sn.notification_id = notification.id
|
|
INNER JOIN do_not_disturb_timings AS dndt ON notification.user_id = dndt.user_id
|
|
AND dndt.ends_at <= :now
|
|
SQL
|
|
|
|
now = Time.zone.now
|
|
shelved_notification_ids = DB.query_single(sql, now: now)
|
|
shelved_notifications = ShelvedNotification.where(id: shelved_notification_ids)
|
|
shelved_notifications.each(&:process)
|
|
shelved_notifications.destroy_all
|
|
|
|
DB.exec("DELETE FROM do_not_disturb_timings WHERE ends_at < :now", now: now)
|
|
end
|
|
end
|
|
end
|