闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
528 B

  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