mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-24 06:46:29 +00:00
25 lines
622 B
Ruby
25 lines
622 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
|
|
code = e.response.code.to_i
|
|
|
|
if (400..499).cover?(code) && ![408, 429].include?(code)
|
|
subscription.destroy!
|
|
else
|
|
raise e
|
|
end
|
|
rescue ActiveRecord::RecordNotFound
|
|
true
|
|
end
|
|
end
|