<commit_before>require 'mongo'

begin
  require 'yajl'
rescue LoadError
  require 'json'
end

require 'resque/errors'

require 'resque/failure'
require 'resque/failure/base'

require 'resque/helpers'
require 'resque/stat'
require 'resque/job'
require 'resque/worker'

module Resque
  include Helpers
  extend self

  # Accepts a 'hostname:port' string or a Redis server.
  def mongo=(server)
    case server
    when String
      host, port = server.split(':')
      @con = Mongo::Connection.new
      @db = @con.db('monque')
      @mongo = @db.collection('monque')
      @workers = @db.collection('workers')
      @failures = @db.collection('failures')
      @stats = @db.collection('stats')

      add_indexes
    else
      raise "I don't know what to do with #{server.inspect}"
    end
  end


  # Returns the current Redis connection. If none has been created, will
  # create a new one.
  def mongo
    return @mongo if @mongo
    self.mongo = 'localhost:27017'
    self.mongo
  end

  def mongo_workers
    return @workers if @workers
    self.mongo = 'localhost:27017'
    @workers
  end
<commit_msg>Use host,port to initialize connection<commit_after>require 'mongo'

begin
  require 'yajl'
rescue LoadError
  require 'json'
end

require 'resque/errors'

require 'resque/failure'
require 'resque/failure/base'

require 'resque/helpers'
require 'resque/stat'
require 'resque/job'
require 'resque/worker'

module Resque
  include Helpers
  extend self

  # Accepts a 'hostname:port' string or a Redis server.
  def mongo=(server)
    case server
    when String
      host, port = server.split(':')
      @con = Mongo::Connection.new(host, port)
      @db = @con.db('monque')
      @mongo = @db.collection('monque')
      @workers = @db.collection('workers')
      @failures = @db.collection('failures')
      @stats = @db.collection('stats')

      add_indexes
    else
      raise "I don't know what to do with #{server.inspect}"
    end
  end


  # Returns the current Redis connection. If none has been created, will
  # create a new one.
  def mongo
    return @mongo if @mongo
    self.mongo = 'localhost:27017'
    self.mongo
  end

  def mongo_workers
    return @workers if @workers
    self.mongo = 'localhost:27017'
    @workers
  end

{'fraction_non_alphanumeric': 0.1083000443852641, 'fraction_numerical': 0.00887705281846427, 'mean_word_length': 3.113138686131387, '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': '6559935', 'n_tokens_mistral': 766, 'n_tokens_neox': 743, 'n_words': 219}