Class: Traject::SolrPool::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/traject/solr_pool/connection.rb

Overview

Reusable persistent-connection seam over http_connection_pool. Owns origin binding and pool_options construction; exposes post/get that borrow a pooled HTTP::Session. A future reader can reuse this unchanged.

Defined Under Namespace

Classes: Options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin:, pool_size:, pool_timeout: nil, **opts) ⇒ Connection

Returns a new instance of Connection.



23
24
25
26
27
28
29
30
31
# File 'lib/traject/solr_pool/connection.rb', line 23

def initialize(origin:, pool_size:, pool_timeout: nil, **opts)
  @origin       = origin
  @pool_size    = pool_size
  @pool_timeout = pool_timeout
  @pool_options = Options.new(headers: opts.fetch(:headers, {}),
                              auth: opts[:auth],
                              timeout: opts[:timeout]).to_pool_opts
  @adapter      = build_adapter
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



21
22
23
# File 'lib/traject/solr_pool/connection.rb', line 21

def origin
  @origin
end

Instance Method Details

#get(path, params: {}, timeout: nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/traject/solr_pool/connection.rb', line 37

def get(path, params: {}, timeout: nil)
  @adapter.with_connection do |conn|
    client = timeout ? conn.timeout(timeout) : conn
    if params.empty?
      client.get(path)
    else
      client.get(path, params: params)
    end
  end
end

#inspectObject Also known as: to_s

Metadata only: never print header values or the auth credential.



53
54
55
56
# File 'lib/traject/solr_pool/connection.rb', line 53

def inspect
  "#<#{self.class} origin=#{@origin} pool_size=#{@pool_size} " \
    "options=[#{@pool_options.keys.join(', ')}]>"
end

#post(path, body:) ⇒ Object



33
34
35
# File 'lib/traject/solr_pool/connection.rb', line 33

def post(path, body:)
  @adapter.with_connection { |conn| conn.post(path, body: body) }
end

#releaseObject



48
49
50
# File 'lib/traject/solr_pool/connection.rb', line 48

def release
  @adapter.release_connection_pool
end