<commit_before># frozen_string_literal: true

class FirebaseCloudMessagingWorker
  include Sidekiq::Worker

  sidekiq_options queue: 'push'

  def perform(notification_id, recipient_id)
    @notification = Notification.find(notification_id)
    @recipient = Account.find(recipient_id)

    I18n.with_locale(@recipient.user.locale || I18n.default_locale) do
      send_push_notifications
    end
  end

  def send_push_notifications
    data = JSON.parse(InlineRenderer.render(@notification, @recipient, 'firebase_cloud_messagings/push_notification'))

    @recipient.user.firebase_cloud_messaging_tokens.each do |firebase_cloud_messaging_token|
      method_name = if firebase_cloud_messaging_token.android?
                      :publish_to_android
                    else
                      :publish_to_ios
                    end

      FirebaseCloudMessagingApi.public_send(method_name, firebase_cloud_messaging_token.token, data)
    end
  end
end<commit_msg>Rescue ActiveRecord::RecordNotFound at FirebaseCloudMessagingWorker<commit_after># frozen_string_literal: true

class FirebaseCloudMessagingWorker
  include Sidekiq::Worker

  sidekiq_options queue: 'push'

  def perform(notification_id, recipient_id)
    @notification = Notification.find(notification_id)
    @recipient = Account.find(recipient_id)

    I18n.with_locale(@recipient.user.locale || I18n.default_locale) do
      send_push_notifications
    end
  rescue ActiveRecord::RecordNotFound
    nil
  end

  def send_push_notifications
    data = JSON.parse(InlineRenderer.render(@notification, @recipient, 'firebase_cloud_messagings/push_notification'))

    @recipient.user.firebase_cloud_messaging_tokens.each do |firebase_cloud_messaging_token|
      method_name = if firebase_cloud_messaging_token.android?
                      :publish_to_android
                    else
                      :publish_to_ios
                    end

      FirebaseCloudMessagingApi.public_send(method_name, firebase_cloud_messaging_token.token, data)
    end
  end
end
{'fraction_non_alphanumeric': 0.06385068762278978, 'fraction_numerical': 0.003929273084479371, 'mean_word_length': 3.640091116173121, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4618140', 'n_tokens_mistral': 635, 'n_tokens_neox': 585, 'n_words': 95}