Class: Erorr::Transport::HTTPAsync

Inherits:
Object
  • Object
show all
Defined in:
lib/erorr/transport/http_async.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHTTPAsync

Returns a new instance of HTTPAsync.



8
9
10
11
# File 'lib/erorr/transport/http_async.rb', line 8

def initialize
  @api_key = Erorr.config.api_key
  @api_url = Erorr.config.api_url
end

Class Method Details

.shut_downObject



18
19
20
21
# File 'lib/erorr/transport/http_async.rb', line 18

def shut_down
  thread_pool.shutdown
  thread_pool.wait_for_termination
end

.thread_poolObject



14
15
16
# File 'lib/erorr/transport/http_async.rb', line 14

def thread_pool
  @thread_pool ||= Concurrent::ThreadPoolExecutor.new(max_threads: 5)
end

Instance Method Details

#deliver(params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/erorr/transport/http_async.rb', line 24

def deliver(params)
  self.class.thread_pool.post do
    uri = URI("#{@api_url}/faults")
    request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
    request.body = {fault: params, api_key: @api_key}.to_json
    Net::HTTP.start(uri.hostname, uri.port) do |http|
      http.request request
    end
  end
end