Sha256: 96e43590bfdad39ebe9d8be3b51c2377ef1e223ddbbbe7f664675d755a4dc801

Contents?: true

Size: 1 KB

Versions: 15

Compression:

Stored size: 1 KB

Contents

require "pg"
require "connection_pool"

module GitLab
  module Exporter
    module Database
      # An abstract class for interacting with DB
      #
      # It takes a connection string (e.g. "dbname=test port=5432")
      class Base
        def self.connection_pool
          @connection_pool ||= Hash.new do |h, connection_string|
            h[connection_string] = ConnectionPool.new(size: 3, timeout: 5) do
              PG.connect(connection_string)
            end
          end
        end

        def initialize(args)
          @connection_string = args[:connection_string]
        end

        def run
          fail NotImplemented
        end

        def connection_pool
          self.class.connection_pool[@connection_string]
        end

        def with_connection_pool
          connection_pool.with do |conn|
            begin
              yield conn
            rescue PG::UnableToSend => e
              conn.reset
              raise e
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gitlab-exporter-7.0.6 lib/gitlab_exporter/database/base.rb
gitlab-exporter-7.0.5 lib/gitlab_exporter/database/base.rb
gitlab-exporter-7.0.4 lib/gitlab_exporter/database/base.rb
gitlab-exporter-7.0.3 lib/gitlab_exporter/database/base.rb
gitlab-exporter-7.0.2 lib/gitlab_exporter/database/base.rb
gitlab-exporter-7.0.1 lib/gitlab_exporter/database/base.rb
gitlab-exporter-7.0.0 lib/gitlab_exporter/database/base.rb
gitlab-exporter-6.1.0 lib/gitlab_exporter/database/base.rb
gitlab-exporter-6.0.0 lib/gitlab_exporter/database/base.rb
gitlab-exporter-5.2.2 lib/gitlab_exporter/database/base.rb
gitlab-exporter-5.2.1 lib/gitlab_exporter/database/base.rb
gitlab-exporter-5.2.0 lib/gitlab_exporter/database/base.rb
gitlab-exporter-5.1.0 lib/gitlab_exporter/database/base.rb
gitlab-exporter-5.0.1 lib/gitlab_exporter/database/base.rb
gitlab-exporter-5.0.0 lib/gitlab_exporter/database/base.rb