Sha256: eae80e2522d286245d483182976c947a5136f2652423ac2f776c6e79a4307c9b

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'delegate'

begin
  require "active_support/isolated_execution_state"
rescue LoadError
  # no-op... Rails 7.0 requires this.
end

begin
  require 'active_support/deprecation'
  require 'active_support/deprecator'
rescue LoadError
end

require 'active_support/core_ext/numeric/time'
require 'net/http/persistent'

require 'artemis/adapters/net_http_adapter'

module Artemis
  module Adapters
    class NetHttpPersistentAdapter < NetHttpAdapter
      attr_reader :_connection, :raw_connection

      def initialize(uri, service_name: , timeout: , pool_size: , adapter_options: {})
        super

        @raw_connection = Net::HTTP::Persistent.new(name: service_name, pool_size: pool_size)
        @raw_connection.open_timeout = timeout
        @raw_connection.read_timeout = timeout
        @raw_connection.idle_timeout = 30.minutes.to_i # TODO: Make it configurable

        @_connection = ConnectionWrapper.new(@raw_connection, uri)
      end

      # Public: Extension point for subclasses to customize the Net:HTTP client
      #
      # Returns a Net::HTTP object
      def connection
        _connection
      end

      class ConnectionWrapper < SimpleDelegator #:nodoc:
        def initialize(obj, url)
          super(obj)

          @url = url
        end

        def request(req)
          __getobj__.request(@url, req)
        end
      end

      private_constant :ConnectionWrapper
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
artemis-1.1.0 lib/artemis/adapters/net_http_persistent_adapter.rb
artemis-1.0.2 lib/artemis/adapters/net_http_persistent_adapter.rb
artemis-1.0.0 lib/artemis/adapters/net_http_persistent_adapter.rb
artemis-0.9.0 lib/artemis/adapters/net_http_persistent_adapter.rb