Sha256: 608f7742a70c70e24c12e5cdcb9261cb27a2b845ff46c94022f1b4609bd6e3b0

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8

module TingYun
  module Agent
    module Database
      # Returns a cached connection for a given ActiveRecord
      # configuration - these are stored or reopened as needed, and if
      # we cannot get one, we ignore it and move on without explaining
      # the sql
      class ConnectionManager
        include Singleton

        def get_connection(config, &connector)
          @connections ||= {}

          connection = @connections[config]

          return connection if connection

          begin
            @connections[config] = connector.call(config)
          rescue => e
            ::TingYun::Agent.logger.error("Caught exception trying to get connection to DB for explain.", e)
            nil
          end
        end

        # Closes all the connections in the internal connection cache
        def close_connections
          @connections ||= {}
          @connections.values.each do |connection|
            begin
              connection.disconnect!
            rescue
            end
          end

          @connections = {}
        end
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tingyun_rpm-3.2.0 lib/ting_yun/agent/database/connection_manager.rb
tingyun_rpm-1.6.1 lib/ting_yun/agent/database/connection_manager.rb
tingyun_rpm-1.5.0 lib/ting_yun/agent/database/connection_manager.rb
tingyun_rpm-1.4.2 lib/ting_yun/agent/database/connection_manager.rb
tingyun_rpm-1.4.1 lib/ting_yun/agent/database/connection_manager.rb
tingyun_rpm-1.3.1 lib/ting_yun/agent/database/connection_manager.rb
tingyun_rpm-1.3.0 lib/ting_yun/agent/database/connection_manager.rb
tingyun_rpm-1.2.0 lib/ting_yun/agent/database/connection_manager.rb