chuckya/app/workers/web/push_notification_worker.rb
han@highemelry 402302776c Change the retry limit in error of web push notification (#11292)
- Change the maximum count of retry for web push notification (Default -> 5).
   - In case of high load of subscribe server, the retries will be repeated many times.
   - Because the retries occupy the default queue, maximum retry count should be reduced.
2019-07-12 18:46:21 +02:00

18 lines
538 B
Ruby

# frozen_string_literal: true
class Web::PushNotificationWorker
include Sidekiq::Worker
sidekiq_options backtrace: true, retry: 5
def perform(subscription_id, notification_id)
subscription = ::Web::PushSubscription.find(subscription_id)
notification = Notification.find(notification_id)
subscription.push(notification) unless notification.activity.nil?
rescue Webpush::ResponseError => e
subscription.destroy! if (400..499).cover?(e.response.code.to_i)
rescue ActiveRecord::RecordNotFound
true
end
end