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.
mastodon/app/workers/web/push_notification_worker.rb

19 lines
528 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class Web::PushNotificationWorker
include Sidekiq::Worker
sidekiq_options backtrace: true
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