push_notification_worker.rb 528 B

123456789101112131415161718
  1. # frozen_string_literal: true
  2. class Web::PushNotificationWorker
  3. include Sidekiq::Worker
  4. sidekiq_options backtrace: true
  5. def perform(subscription_id, notification_id)
  6. subscription = ::Web::PushSubscription.find(subscription_id)
  7. notification = Notification.find(notification_id)
  8. subscription.push(notification) unless notification.activity.nil?
  9. rescue Webpush::ResponseError => e
  10. subscription.destroy! if (400..499).cover?(e.response.code.to_i)
  11. rescue ActiveRecord::RecordNotFound
  12. true
  13. end
  14. end