2018-05-11 19:49:12 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Web::PushNotificationWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2019-07-13 02:46:21 +10:00
|
|
|
sidekiq_options backtrace: true, retry: 5
|
2018-05-11 19:49:12 +10: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-17 13:14:13 +11:00
|
|
|
rescue Webpush::ResponseError => e
|
|
|
|
subscription.destroy! if (400..499).cover?(e.response.code.to_i)
|
2018-05-11 19:49:12 +10:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|