about summary refs log tree commit diff
path: root/app/workers/web/push_notification_worker.rb
blob: 4a40e5c8bd98f49f1e7e8a281cad23fa9831fb00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

class Web::PushNotificationWorker
  include Sidekiq::Worker

  sidekiq_options backtrace: true

  def perform(subscription_id, notification_id)
    subscription = ::Web::PushSubscription.find(subscription_id)
    notification = Notification.find(notification_id)

    subscription.push(notification) unless notification.activity.nil?
  rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription
    subscription.destroy!
  rescue ActiveRecord::RecordNotFound
    true
  end
end