lib/staccato/rack/faraday_http_adapter.rb in staccato-rack-0.4.0 vs lib/staccato/rack/faraday_http_adapter.rb in staccato-rack-0.4.1

- old
+ new

@@ -11,16 +11,26 @@ faraday.response :logger, @logger if @logger faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end - def post(data) - Thread.new(data) do |body_data| - @conn.post do |req| - req.url '/collect' - req.options.timeout = 1 # open/read timeout in seconds - req.body = body_data + def post(data, url = '/collect') + Thread.new(data, url) do + begin + execute(data, url) + rescue => e + @logger.error "Could not collect #{data.inspect} => #{e.message}" end + end + end + + private + + def execute(post_data, post_url) + @conn.post do |req| + req.url post_url + req.options.timeout = 2 # open/read timeout in seconds + req.body = post_data end end end end end