<commit_before>class TagRepublisher
  def republish_tags(tags)
    log "Sending #{tags.count} tags to the publishing-api"

    done = 0
    tags.find_each do |tag|
      republish_tag(tag)

      done += 1

      if done % 100 == 0
        log "#{done} completed..."
      end
    end

    log "Done: #{done} tags sent to publishing-api."

    log "Sending root browse page to publishing-api"
    publishing_api.put_content_item(
      "/browse",
      RootBrowsePagePresenter.new.render_for_publishing_api
    )

    log "All done"
  end

private

  def republish_tag(tag)
    retries = 0

    begin
      PublishingAPINotifier.new(tag).send_single_tag_to_publishing_api
    rescue GdsApi::TimedOutException, Timeout::Error => e
      retries += 1
      if retries <= 3
        log "Timeout (tag #{tag.base_path}): retry #{retries}"
        sleep 0.5
        retry
      end
      raise
    end
  end

  def publishing_api
    CollectionsPublisher.services(:publishing_api)
  end

  def log(string)
    Rails.logger.info(string)
  end
end
<commit_msg>Also retry publishing of root browse page<commit_after>class TagRepublisher
  def republish_tags(tags)
    log "Sending #{tags.count} tags to the publishing-api"

    done = 0
    tags.find_each do |tag|
      republish_tag(tag)

      done += 1

      if done % 100 == 0
        log "#{done} completed..."
      end
    end

    log "Done: #{done} tags sent to publishing-api."

    log "Sending root browse page to publishing-api"
    with_retry do
      publishing_api.put_content_item(
        "/browse",
        RootBrowsePagePresenter.new.render_for_publishing_api
      )
    end

    log "All done"
  end

private

  def republish_tag(tag)
    with_retry do
      PublishingAPINotifier.new(tag).send_single_tag_to_publishing_api
    end
  end

  def with_retry
    retries = 0

    begin
      yield
    rescue GdsApi::TimedOutException, Timeout::Error => e
      retries += 1
      if retries <= 3
        log "Timeout: retry #{retries}"
        sleep 0.5
        retry
      end
      raise
    end
  end

  def publishing_api
    CollectionsPublisher.services(:publishing_api)
  end

  def log(string)
    Rails.logger.info(string)
  end
end

{'fraction_non_alphanumeric': 0.08253968253968254, 'fraction_numerical': 0.009977324263038548, 'mean_word_length': 2.38863287250384, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5501728', 'n_tokens_mistral': 761, 'n_tokens_neox': 720, 'n_words': 188}