<commit_before># frozen_string_literal: true

class WebPushNotificationWorker
  include Sidekiq::Worker

  sidekiq_options backtrace: true

  def perform(session_activation_id, notification_id)
    session_activation = SessionActivation.find(session_activation_id)
    notification = Notification.find(notification_id)

    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)

      raise e
    end
  end
end<commit_msg>fix(web_push_notification_worker): Guard against deleted notifications (#4379)<commit_after># frozen_string_literal: true

class WebPushNotificationWorker
  include Sidekiq::Worker

  sidekiq_options backtrace: true

  def perform(session_activation_id, notification_id)
    session_activation = SessionActivation.find(session_activation_id)
    notification = Notification.find(notification_id)

    return if session_activation.nil? || notification.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)

      raise e
    end
  end
end
{'fraction_non_alphanumeric': 0.058403634003893576, 'fraction_numerical': 0.0025957170668397143, 'mean_word_length': 5.319672131147541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5384900', 'n_tokens_mistral': 419, 'n_tokens_neox': 399, 'n_words': 88}