diff options
author | Sorin Davidoi <sorin.davidoi@gmail.com> | 2017-07-18 16:25:40 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-07-18 16:25:40 +0200 |
commit | 8387b3928ec7658192907da79df65e65aaa8a7fc (patch) | |
tree | 87df6e1941444eae5ae44856cd0f2e4e857213ac /app/workers | |
parent | afa52e4d636f8fdc4b21b90e4f006d8ea434b4e9 (diff) |
fix(push-subscriptions): Refactor how Sidekiq jobs are handled (#4226)
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/web_push_notification_worker.rb | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/app/workers/web_push_notification_worker.rb b/app/workers/web_push_notification_worker.rb index e8f1d72bd..da4043ddb 100644 --- a/app/workers/web_push_notification_worker.rb +++ b/app/workers/web_push_notification_worker.rb @@ -5,22 +5,18 @@ class WebPushNotificationWorker sidekiq_options backtrace: true - def perform(recipient_id, notification_id) - recipient = Account.find(recipient_id) + def perform(session_activation_id, notification_id) + session_activation = SessionActivation.find(session_activation_id) notification = Notification.find(notification_id) - sessions_with_subscriptions = recipient.user.session_activations.where.not(web_push_subscription: nil) + begin + session_activation.web_push_subscription.push(notification) + rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription => e + # Subscription expiration is not currently implemented in any browser + session_activation.web_push_subscription.destroy! + session_activation.update!(web_push_subscription: nil) - sessions_with_subscriptions.each do |session| - begin - session.web_push_subscription.push(notification) - rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription - # Subscription expiration is not currently implemented in any browser - session.web_push_subscription.destroy! - session.update!(web_push_subscription: nil) - rescue Webpush::PayloadTooLarge => e - Rails.logger.error(e) - end + raise e end end end |