<commit_before>require 'cgi'
require 'open-uri'

module TopholdRack

  class Redispatcher

    def initialize app
      @app = app
    end

    def request_black_list 
      @black_list ||= /^\/(#{Rails.configuration.tophold_rack_request_black_list.join('|')})/
    end

    def call env
      unless Rails.configuration.tophold_rack_disabled
        request = Rack::Request.new env
        if request.get?
          path, query = request.path, request.query_string
          if scope = env["rack.session"]["warden.user.#{Rails.configuration.tophold_rack_devise_scope}.key"]
            user_id = scope[1][0].to_s =~ /\d+/ ? scope[1][0] : scope[0][0]
          else
            user_id = nil
          end
          unless path =~ request_black_list            
            str = "#{path.blank? ? '/' : path}?query=#{query}&user_id=#{user_id}" 
            url = Rails.configuration.tophold_rack_tracking_url+"?request_url=#{CGI.escape str}"
            open url
          end
        end
      end
      @app.call env #pass the buckets
    end
  
  end

end
<commit_msg>Added rescue when opening url.<commit_after>require 'cgi'
require 'open-uri'

module TopholdRack

  class Redispatcher

    def initialize app
      @app = app
    end

    def request_black_list 
      @black_list ||= /^\/(#{Rails.configuration.tophold_rack_request_black_list.join('|')})/
    end

    def call env
      unless Rails.configuration.tophold_rack_disabled
        request = Rack::Request.new env
        if request.get?
          path, query = request.path, request.query_string
          if scope = env["rack.session"]["warden.user.#{Rails.configuration.tophold_rack_devise_scope}.key"]
            user_id = scope[1][0].to_s =~ /\d+/ ? scope[1][0] : scope[0][0]
          else
            user_id = nil
          end
          unless path =~ request_black_list            
            str = "#{path.blank? ? '/' : path}?query=#{query}&user_id=#{user_id}" 
            url = Rails.configuration.tophold_rack_tracking_url+"?request_url=#{CGI.escape str}"
            begin
              open url
            rescue Exception => e
              Rails.logger.fatal 'RedisDispatcher can not work!'
            end
          end
        end
      end
      @app.call env #pass the buckets
    end
  
  end

end

{'fraction_non_alphanumeric': 0.11333914559721012, 'fraction_numerical': 0.0052310374891020054, 'mean_word_length': 2.072289156626506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '224271', 'n_tokens_mistral': 745, 'n_tokens_neox': 711, 'n_words': 148}