This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2018-05-11 02:49:12 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Web::PushNotificationWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2019-07-12 09:46:21 -07:00
|
|
|
sidekiq_options backtrace: true, retry: 5
|
2018-05-11 02:49:12 -07:00
|
|
|
|
|
|
|
def perform(subscription_id, notification_id)
|
|
|
|
subscription = ::Web::PushSubscription.find(subscription_id)
|
|
|
|
notification = Notification.find(notification_id)
|
|
|
|
|
|
|
|
subscription.push(notification) unless notification.activity.nil?
|
2018-12-16 18:14:13 -08:00
|
|
|
rescue Webpush::ResponseError => e
|
2019-09-13 10:15:47 -07:00
|
|
|
code = e.response.code.to_i
|
|
|
|
|
|
|
|
if (400..499).cover?(code) && ![408, 429].include?(code)
|
|
|
|
subscription.destroy!
|
|
|
|
else
|
|
|
|
raise e
|
|
|
|
end
|
2018-05-11 02:49:12 -07:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|