Sha256: 4a0e0a1b912e4114fa1fc9781894666a129ead66dfe949a85750def630f57193

Contents?: true

Size: 1.41 KB

Versions: 39

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'connection_pool'

module Vmpooler
  class PoolManager
    class GenericConnectionPool < ConnectionPool
      # Extend the ConnectionPool class with instrumentation
      # https://github.com/mperham/connection_pool/blob/master/lib/connection_pool.rb

      def initialize(options = {}, &block)
        super(options, &block)
        @metrics = options[:metrics]
        @connpool_type = options[:connpool_type]
        @connpool_type = 'connectionpool' if @connpool_type.nil? || @connpool_type == ''
        @connpool_provider = options[:connpool_provider]
        @connpool_provider = 'unknown' if @connpool_provider.nil? || @connpool_provider == ''
      end

      def with_metrics(options = {})
        Thread.handle_interrupt(Exception => :never) do
          start = Time.now
          conn = checkout(options)
          timespan_ms = ((Time.now - start) * 1000).to_i
          @metrics&.gauge("connection_available.#{@connpool_type}.#{@connpool_provider}", @available.length)
          @metrics&.timing("connection_waited.#{@connpool_type}.#{@connpool_provider}", timespan_ms)
          begin
            Thread.handle_interrupt(Exception => :immediate) do
              yield conn
            end
          ensure
            checkin
            @metrics&.gauge("connection_available.#{@connpool_type}.#{@connpool_provider}", @available.length)
          end
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
vmpooler-3.6.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-3.5.1 lib/vmpooler/generic_connection_pool.rb
vmpooler-3.5.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-3.4.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-3.3.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-3.2.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-3.1.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-3.0.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-2.5.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-2.4.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-2.3.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-2.2.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-2.1.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-2.0.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-1.3.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-1.2.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-1.1.2 lib/vmpooler/generic_connection_pool.rb
vmpooler-1.1.1 lib/vmpooler/generic_connection_pool.rb
vmpooler-1.1.0 lib/vmpooler/generic_connection_pool.rb
vmpooler-1.0.0 lib/vmpooler/generic_connection_pool.rb