web_push_notification_worker.rb 789 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class WebPushNotificationWorker
  3. include Sidekiq::Worker
  4. sidekiq_options backtrace: true
  5. def perform(session_activation_id, notification_id)
  6. session_activation = SessionActivation.find(session_activation_id)
  7. notification = Notification.find(notification_id)
  8. return if session_activation.web_push_subscription.nil? || notification.activity.nil?
  9. session_activation.web_push_subscription.push(notification)
  10. rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription
  11. # Subscription expiration is not currently implemented in any browser
  12. session_activation.web_push_subscription.destroy!
  13. session_activation.update!(web_push_subscription: nil)
  14. true
  15. rescue ActiveRecord::RecordNotFound
  16. true
  17. end
  18. end