module ThinkingSphinx::Connection

Constants

MAXIMUM_RETRIES

Public Class Methods

connection_class() click to toggle source
# File lib/thinking_sphinx/connection.rb, line 19
def self.connection_class
  return ThinkingSphinx::Connection::JRuby if RUBY_PLATFORM == 'java'

  ThinkingSphinx::Connection::MRI
end
new() click to toggle source
# File lib/thinking_sphinx/connection.rb, line 6
def self.new
  configuration = ThinkingSphinx::Configuration.instance

  options = {
    :host      => configuration.searchd.address,
    :port      => configuration.searchd.mysql41,
    :socket    => configuration.searchd.socket,
    :reconnect => true
  }.merge(configuration.settings['connection_options'] || {})

  connection_class.new options
end
persistent=(persist) click to toggle source
# File lib/thinking_sphinx/connection.rb, line 60
def self.persistent=(persist)
  @persistent = persist
end
persistent?() click to toggle source
# File lib/thinking_sphinx/connection.rb, line 56
def self.persistent?
  @persistent
end
pool() click to toggle source
# File lib/thinking_sphinx/connection.rb, line 25
def self.pool
  @pool ||= Innertube::Pool.new(
    Proc.new { ThinkingSphinx::Connection.new },
    Proc.new { |connection| connection.close! }
  )
end
take() { |connection| ... } click to toggle source
# File lib/thinking_sphinx/connection.rb, line 32
def self.take
  retries  = 0
  original = nil
  begin
    pool.take do |connection|
      begin
        yield connection
      rescue ThinkingSphinx::QueryExecutionError, connection.base_error => error
        original = ThinkingSphinx::SphinxError.new_from_mysql error
        retries += MAXIMUM_RETRIES if original.is_a?(ThinkingSphinx::QueryError)
        raise Innertube::Pool::BadResource
      end
    end
  rescue Innertube::Pool::BadResource
    retries += 1
    raise original unless retries < MAXIMUM_RETRIES

    ActiveSupport::Notifications.instrument(
      "message.thinking_sphinx", :message => "Retrying query \"#{original.statement}\" after error: #{original.message}"
    )
    retry
  end
end