about summary refs log tree commit diff
path: root/app/workers/web/push_notification_worker.rb
blob: 8e8a359735674ea753a6b0fed60b5ab71f90cf9a (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::ResponseError => e
    subscription.destroy! if (400..499).cover?(e.response.code.to_i)
  rescue ActiveRecord::RecordNotFound
    true
  end
end