Module: Noiseless::Adapters::ExecutionModules::HttpTransport

Included in:
EsCompatibleExecution, TypesenseExecution
Defined in:
lib/noiseless/adapters/execution_modules/http_transport.rb

Overview

Shared Async::HTTP connection handling for HTTP-based adapters. Host classes must provide a private default_port method.

Instance Method Summary collapse

Instance Method Details

#closeObject



25
26
27
# File 'lib/noiseless/adapters/execution_modules/http_transport.rb', line 25

def close
  @clients&.each_value(&:close)
end

#initialize(hosts: [], **connection_params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/noiseless/adapters/execution_modules/http_transport.rb', line 9

def initialize(hosts: [], **connection_params)
  # Ensure we always have at least one host
  hosts_array = Array(hosts)
  @hosts = hosts_array.empty? ? ["http://localhost:#{default_port}"] : hosts_array
  @connection_params = connection_params

  # Initialize HTTP clients for each host
  @clients = {}
  @hosts.each do |host|
    endpoint = Async::HTTP::Endpoint.parse(host)
    @clients[host] = Async::HTTP::Client.new(endpoint)
  end

  super(hosts: @hosts, **connection_params)
end