Class: Nadir::Transport::HTTPAsync
- Inherits:
-
Object
- Object
- Nadir::Transport::HTTPAsync
- Defined in:
- lib/nadir/transport/http_async.rb
Class Method Summary collapse
Instance Method Summary collapse
- #deliver(params) ⇒ Object
-
#initialize ⇒ HTTPAsync
constructor
A new instance of HTTPAsync.
Constructor Details
Class Method Details
.shut_down ⇒ Object
19 20 21 22 |
# File 'lib/nadir/transport/http_async.rb', line 19 def shut_down thread_pool.shutdown thread_pool.wait_for_termination end |
.thread_pool ⇒ Object
15 16 17 |
# File 'lib/nadir/transport/http_async.rb', line 15 def thread_pool @thread_pool ||= Concurrent::ThreadPoolExecutor.new(max_threads: 5) end |
Instance Method Details
#deliver(params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nadir/transport/http_async.rb', line 25 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 |