Browse Source

Better Druid timeout and error handling

Andrew Kane 6 years ago
parent
commit
9ddbd14e2b
1 changed files with 6 additions and 5 deletions
  1. 6 5
      lib/blazer/adapters/druid_adapter.rb

+ 6 - 5
lib/blazer/adapters/druid_adapter.rb

@@ -10,21 +10,22 @@ module Blazer
 
         header = {"Content-Type" => "application/json", "Accept" => "application/json"}
         context = {}
-        if data_source.timeout
-          context = data_source.timeout.to_i * 1000
-        end
+        timeout = data_source.timeout ? data_source.timeout.to_i : 300
         data = {
           query: statement,
-          context: context
+          context: {
+            timeout: timeout
+          }
         }
 
         uri = URI.parse("#{settings["url"]}/druid/v2/sql/")
         http = Net::HTTP.new(uri.host, uri.port)
+        http.read_timeout = timeout
 
         begin
           response = JSON.parse(http.post(uri.request_uri, data.to_json, header).body)
           if response.is_a?(Hash)
-            error = response["errorMessage"]
+            error = response["errorMessage"] || "Unknown error: #{response.inspect}"
             if error.include?("timed out")
               error = Blazer::TIMEOUT_MESSAGE
             end