Class: Jobs::ProcessShelvedNotifications

Inherits:
Scheduled show all
Defined in:
app/jobs/scheduled/process_shelved_notifications.rb

Instance Method Summary collapse

Methods inherited from Scheduled

#perform

Methods inherited from Base

acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately

Instance Method Details

#execute(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/jobs/scheduled/process_shelved_notifications.rb', line 7

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