<commit_before>class PublishingApiWorker < WorkerBase
  sidekiq_options queue: "publishing_api"
  include LockedDocumentConcern

  def perform(model_name,
              id,
              update_type = nil,
              locale = I18n.default_locale.to_s,
              bulk_publishing = false)

    model = class_for(model_name).unscoped.find_by(id: id)
    return if model.nil?

    if model.is_a?(Edition)
      check_if_locked_document(edition: model)
    end

    presenter = PublishingApiPresenters.presenter_for(model, update_type: update_type)

    I18n.with_locale(locale) do
      begin
        send_item(presenter, locale, bulk_publishing)
      rescue GdsApi::HTTPClientError => e
        handle_client_error(e)
      end
    end
  end

private

  def class_for(model_name)
    model_name.constantize
  end
<commit_msg>Don't send Publishing API HTTP conflict errors to Sentry<commit_after>class PublishingApiWorker < WorkerBase
  sidekiq_options queue: "publishing_api"
  include LockedDocumentConcern

  def perform(model_name,
              id,
              update_type = nil,
              locale = I18n.default_locale.to_s,
              bulk_publishing = false)

    model = class_for(model_name).unscoped.find_by(id: id)
    return if model.nil?

    if model.is_a?(Edition)
      check_if_locked_document(edition: model)
    end

    presenter = PublishingApiPresenters.presenter_for(model, update_type: update_type)

    I18n.with_locale(locale) do
      begin
        send_item(presenter, locale, bulk_publishing)
      rescue GdsApi::HTTPConflict => e
        # The Publishing API sometimes returns: Cannot publish an
        # already published edition. Ideally we'd avoid this error,
        # but for now, just avoid recording it in Sentry, as it's
        # not actionable.
        logger.error "PublishingApiWorker: HTTPConflict: #{e.message}"
      rescue GdsApi::HTTPClientError => e
        handle_client_error(e)
      end
    end
  end

private

  def class_for(model_name)
    model_name.constantize
  end

{'fraction_non_alphanumeric': 0.06866110838646396, 'fraction_numerical': 0.00392349190779794, 'mean_word_length': 2.8783269961977185, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '2631155', 'n_tokens_mistral': 640, 'n_tokens_neox': 619, 'n_words': 145}