require 'net/http' require 'net/https' require 'uri' require 'concurrent' module Nadir module Transport class HTTPAsync def initialize @api_key = Nadir.config.api_key @api_url = Nadir.config.api_url end class << self def thread_pool @thread_pool ||= Concurrent::ThreadPoolExecutor.new(max_threads: 5) end def shut_down thread_pool.shutdown thread_pool.wait_for_termination end end def deliver(params) self.class.thread_pool.post do uri = URI("#{@api_url}/faults") post = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') post.body = {fault: params, api_key: @api_key}.to_json request = Net::HTTP.new(uri.hostname, uri.port) request.use_ssl = true response = request.start do |http| http.request post end end end end end end