about summary refs log tree commit diff
path: root/app/workers/web/push_notification_worker.rb
blob: 90104397581aacdcf9f21c58f518c1849bc2c6e0 (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, retry: 5

  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